Submission #930436
Source Code Expand
#include <stdio.h> #include <map> #include <set> #include <vector> using namespace std; const long long mod = 1000000007; long long comb[505][505], phi[505], pw[505], inv[505]; int N, M, K; vector<int> G[505],I[505]; int par[505], chk[505]; vector<int> k,p; int find(int x) { if (par[x] != x) par[x] = find(par[x]); return par[x]; } void dfs(int x) { for (int i=0;i<G[x].size();i++){ int y = G[x][i]; if (chk[y]){ bool good = 0; for (int j=0;j<k.size();j++) if (k[j] == y) good = 1; if (good) for (int j=(int)p.size()-1;j>=0;j--){ par[(find(p[j]))] = find(I[x][i]); if (k[j] == y) break; } } else{ k.push_back(x); p.push_back(I[x][i]); chk[x] = 1; dfs(y); k.pop_back(); p.pop_back(); } } } int main() { scanf("%d %d %d", &N, &M, &K); for (int i=0;i<505;i++){ comb[i][0] = comb[i][i] = 1; for (int j=1;j<i;j++) comb[i][j] = (comb[i-1][j-1] + comb[i-1][j]) % mod; } for (int i=1;i<505;i++) phi[i] = i; for (int i=1;i<505;i++){ for (int j=i*2;j<505;j+=i) phi[j] = (phi[j] + mod - phi[i]) % mod; } pw[0] = 1; for (int i=1;i<505;i++) pw[i] = pw[i-1] * K % mod; inv[1] = 1; for (int i=2;i<505;i++) inv[i] = (mod - mod / i) * inv[mod % i] % mod; for (int i=1;i<=M;i++){ int x, y; scanf("%d %d", &x, &y); G[x].push_back(y); I[x].push_back(i); G[y].push_back(x); I[y].push_back(i); } for (int i=1;i<=M;i++) par[i] = i; for (int i=1;i<=N;i++) if (!chk[i]) { dfs(i); } long long ans = 1; map<int, int> sz; map<int, set<int> > vt; for (int i=1;i<=M;i++){ sz[find(i)]++; } for (int i=1;i<=N;i++) for (int j=0;j<I[i].size();j++) vt[find(I[i][j])].insert(G[i][j]); for (auto &p : sz){ if (vt[p.first].size() == p.second){ long long c = 0; for (int d=1;d<=p.second;d++) if (p.second % d == 0){ c = (c + phi[d] * pw[p.second/d]) % mod; } c = c * inv[p.second] % mod; ans = ans * c % mod; } else{ ans = ans * comb[p.second+K-1][K-1] % mod; } } printf("%lld\n", ans); return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Painting Graphs with AtCoDeer |
User | august14 |
Language | C++14 (GCC 5.4.1) |
Score | 1300 |
Code Size | 2103 Byte |
Status | AC |
Exec Time | 5 ms |
Memory | 2432 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:46:31: 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:35: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] int x, y; scanf("%d %d", &x, &y); ^
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 | 5 ms | 2304 KB |
0_001.txt | AC | 4 ms | 2304 KB |
0_002.txt | AC | 5 ms | 2304 KB |
1_003.txt | AC | 5 ms | 2304 KB |
1_004.txt | AC | 5 ms | 2304 KB |
1_005.txt | AC | 5 ms | 2304 KB |
1_006.txt | AC | 5 ms | 2304 KB |
1_007.txt | AC | 5 ms | 2304 KB |
1_008.txt | AC | 5 ms | 2304 KB |
1_009.txt | AC | 5 ms | 2304 KB |
1_010.txt | AC | 5 ms | 2304 KB |
1_011.txt | AC | 5 ms | 2304 KB |
1_012.txt | AC | 5 ms | 2304 KB |
1_013.txt | AC | 5 ms | 2304 KB |
1_014.txt | AC | 5 ms | 2304 KB |
1_015.txt | AC | 5 ms | 2304 KB |
1_016.txt | AC | 5 ms | 2304 KB |
1_017.txt | AC | 5 ms | 2304 KB |
1_018.txt | AC | 4 ms | 2304 KB |
1_019.txt | AC | 5 ms | 2304 KB |
1_020.txt | AC | 4 ms | 2304 KB |
1_021.txt | AC | 5 ms | 2304 KB |
1_022.txt | AC | 5 ms | 2304 KB |
1_023.txt | AC | 5 ms | 2304 KB |
1_024.txt | AC | 5 ms | 2304 KB |
1_025.txt | AC | 5 ms | 2304 KB |
1_026.txt | AC | 5 ms | 2304 KB |
1_027.txt | AC | 5 ms | 2304 KB |
1_028.txt | AC | 5 ms | 2304 KB |
1_029.txt | AC | 5 ms | 2304 KB |
1_030.txt | AC | 5 ms | 2304 KB |
1_031.txt | AC | 5 ms | 2304 KB |
1_032.txt | AC | 5 ms | 2304 KB |
1_033.txt | AC | 5 ms | 2304 KB |
1_034.txt | AC | 5 ms | 2304 KB |
1_035.txt | AC | 5 ms | 2304 KB |
1_036.txt | AC | 5 ms | 2304 KB |
1_037.txt | AC | 5 ms | 2304 KB |
1_038.txt | AC | 5 ms | 2304 KB |
1_039.txt | AC | 5 ms | 2304 KB |
1_040.txt | AC | 4 ms | 2304 KB |
1_041.txt | AC | 5 ms | 2304 KB |
1_042.txt | AC | 5 ms | 2304 KB |
1_043.txt | AC | 5 ms | 2304 KB |
1_044.txt | AC | 5 ms | 2304 KB |
1_045.txt | AC | 5 ms | 2304 KB |
1_046.txt | AC | 4 ms | 2304 KB |
1_047.txt | AC | 5 ms | 2304 KB |
1_048.txt | AC | 5 ms | 2304 KB |
1_049.txt | AC | 5 ms | 2304 KB |
1_050.txt | AC | 5 ms | 2304 KB |
1_051.txt | AC | 5 ms | 2304 KB |
1_052.txt | AC | 5 ms | 2304 KB |
1_053.txt | AC | 5 ms | 2304 KB |
1_054.txt | AC | 5 ms | 2304 KB |
1_055.txt | AC | 5 ms | 2304 KB |
1_056.txt | AC | 5 ms | 2304 KB |
1_057.txt | AC | 5 ms | 2304 KB |
1_058.txt | AC | 4 ms | 2304 KB |
1_059.txt | AC | 5 ms | 2304 KB |
1_060.txt | AC | 5 ms | 2432 KB |
1_061.txt | AC | 5 ms | 2304 KB |
1_062.txt | AC | 5 ms | 2304 KB |
1_063.txt | AC | 5 ms | 2304 KB |