Submission #931456
Source Code Expand
#include<stdio.h> #include<algorithm> #include<vector> using namespace std; int n, m, K, Num[60], cnt, Up[60], Ch[60][60]; int C, D[60], D2[60], Root[60]; long long Mod = 1000000007, po[110]; vector<int>E[60]; void DFS(int a){ int i, x; Num[a] = ++cnt; Up[a] = cnt; for(i=0;i<E[a].size();i++){ x = E[a][i]; if(Num[x]){ Up[a] = min(Up[a], Num[x]); continue; } Ch[a][x] = 1; DFS(x); Up[a] = min(Up[a], Up[x]); if(Up[x] >= Num[a]){ Ch[a][x] = 2; } } } void Do(int a, int pp, int c){ int i, x; for(i=0;i<E[a].size();i++){ x = E[a][i]; if(x==pp)continue; if(Num[x] < Num[a]){ D2[c]++; continue; } if(!Ch[a][x])continue; if(Ch[a][x] == 1){ D[c]++,D2[c]++; Do(x, a, c); } else{ C++; D[C]=2,D2[C] = 1; Do(x, a, C); } } } int gcd(int a, int b){ return b?gcd(b,a%b):a; } long long Inv(long long a){ int b = Mod-2; long long r = 1; while(b){ if(b&1)r=r*a%Mod; a=a*a%Mod;b>>=1; } return r; } int main(){ int i, a, b, j; long long res = 1; scanf("%d%d%d",&n,&m,&K); for(i=0;i<m;i++){ scanf("%d%d",&a,&b); E[a].push_back(b); E[b].push_back(a); } po[0]=1; for(i=1;i<=100;i++){ po[i]=po[i-1]*K%Mod; } for(i=1;i<=n;i++){ if(!Num[i]){ DFS(i); Root[i] = 1; } } for(i=1;i<=n;i++){ if(Root[i]){ Do(i,-1,0); } } for(i=1;i<=C;i++){ if(D2[i] == D[i] - 1){ res = res * po[D2[i]] % Mod; continue; } if(D2[i] != D[i]){ for(j=1;j<=D2[i];j++){ res = res * (K-1+j)%Mod; res = res * Inv(j)%Mod; } } else{ long long s = 0; for(j=1;j<=D[i];j++){ s = (s+po[gcd(j,D[i])])%Mod; } s = s * Inv(D[i])%Mod; res = res * s %Mod; } } printf("%lld\n",res); }
Submission Info
Submission Time | |
---|---|
Task | F - Painting Graphs with AtCoDeer |
User | ainta |
Language | C++14 (GCC 5.4.1) |
Score | 1300 |
Code Size | 2310 Byte |
Status | AC |
Exec Time | 3 ms |
Memory | 256 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:63:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d%d",&n,&m,&K); ^ ./Main.cpp:65:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d",&a,&b); ^
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1300 / 1300 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_000.txt, 0_001.txt, 0_002.txt |
All | 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt, 1_026.txt, 1_027.txt, 1_028.txt, 1_029.txt, 1_030.txt, 1_031.txt, 1_032.txt, 1_033.txt, 1_034.txt, 1_035.txt, 1_036.txt, 1_037.txt, 1_038.txt, 1_039.txt, 1_040.txt, 1_041.txt, 1_042.txt, 1_043.txt, 1_044.txt, 1_045.txt, 1_046.txt, 1_047.txt, 1_048.txt, 1_049.txt, 1_050.txt, 1_051.txt, 1_052.txt, 1_053.txt, 1_054.txt, 1_055.txt, 1_056.txt, 1_057.txt, 1_058.txt, 1_059.txt, 1_060.txt, 1_061.txt, 1_062.txt, 1_063.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_000.txt | AC | 3 ms | 256 KB |
0_001.txt | AC | 3 ms | 256 KB |
0_002.txt | AC | 3 ms | 256 KB |
1_003.txt | AC | 3 ms | 256 KB |
1_004.txt | AC | 3 ms | 256 KB |
1_005.txt | AC | 3 ms | 256 KB |
1_006.txt | AC | 3 ms | 256 KB |
1_007.txt | AC | 3 ms | 256 KB |
1_008.txt | AC | 3 ms | 256 KB |
1_009.txt | AC | 3 ms | 256 KB |
1_010.txt | AC | 3 ms | 256 KB |
1_011.txt | AC | 3 ms | 256 KB |
1_012.txt | AC | 3 ms | 256 KB |
1_013.txt | AC | 3 ms | 256 KB |
1_014.txt | AC | 3 ms | 256 KB |
1_015.txt | AC | 3 ms | 256 KB |
1_016.txt | AC | 3 ms | 256 KB |
1_017.txt | AC | 3 ms | 256 KB |
1_018.txt | AC | 3 ms | 256 KB |
1_019.txt | AC | 3 ms | 256 KB |
1_020.txt | AC | 3 ms | 256 KB |
1_021.txt | AC | 3 ms | 256 KB |
1_022.txt | AC | 3 ms | 256 KB |
1_023.txt | AC | 3 ms | 256 KB |
1_024.txt | AC | 3 ms | 256 KB |
1_025.txt | AC | 3 ms | 256 KB |
1_026.txt | AC | 3 ms | 256 KB |
1_027.txt | AC | 3 ms | 256 KB |
1_028.txt | AC | 3 ms | 256 KB |
1_029.txt | AC | 3 ms | 256 KB |
1_030.txt | AC | 3 ms | 256 KB |
1_031.txt | AC | 3 ms | 256 KB |
1_032.txt | AC | 3 ms | 256 KB |
1_033.txt | AC | 3 ms | 256 KB |
1_034.txt | AC | 3 ms | 256 KB |
1_035.txt | AC | 3 ms | 256 KB |
1_036.txt | AC | 3 ms | 256 KB |
1_037.txt | AC | 3 ms | 256 KB |
1_038.txt | AC | 3 ms | 256 KB |
1_039.txt | AC | 3 ms | 256 KB |
1_040.txt | AC | 3 ms | 256 KB |
1_041.txt | AC | 3 ms | 256 KB |
1_042.txt | AC | 3 ms | 256 KB |
1_043.txt | AC | 3 ms | 256 KB |
1_044.txt | AC | 3 ms | 256 KB |
1_045.txt | AC | 3 ms | 256 KB |
1_046.txt | AC | 3 ms | 256 KB |
1_047.txt | AC | 3 ms | 256 KB |
1_048.txt | AC | 3 ms | 256 KB |
1_049.txt | AC | 3 ms | 256 KB |
1_050.txt | AC | 3 ms | 256 KB |
1_051.txt | AC | 3 ms | 256 KB |
1_052.txt | AC | 3 ms | 256 KB |
1_053.txt | AC | 3 ms | 256 KB |
1_054.txt | AC | 3 ms | 256 KB |
1_055.txt | AC | 3 ms | 256 KB |
1_056.txt | AC | 3 ms | 256 KB |
1_057.txt | AC | 3 ms | 256 KB |
1_058.txt | AC | 3 ms | 256 KB |
1_059.txt | AC | 3 ms | 256 KB |
1_060.txt | AC | 3 ms | 256 KB |
1_061.txt | AC | 3 ms | 256 KB |
1_062.txt | AC | 3 ms | 256 KB |
1_063.txt | AC | 3 ms | 256 KB |