Submission #1635225
Source Code Expand
// Painting Graphs with AtCoDeer // * frank_c1 // * 2017 / 09 / 30 #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> pii; const int maxn = 205; const int mo = (int)(1e9) + 7; int C[maxn][maxn], pw[maxn], inv[maxn]; int dfn[maxn], low[maxn], top; vector<int> nxt[maxn]; pii stk[maxn]; int K, idx; LL ret = 1; void chk(int u, int v) { int cnt = 0, s = stk[top].second, succ = 1, lst = 0; while (top && stk[top] != make_pair(u, v)) { ++cnt; if (lst && lst != stk[top].second) succ = 0; lst = stk[top].first; --top; } if (stk[top] == make_pair(u, v)) { ++cnt; if (lst && lst != stk[top].second) succ = 0; lst = stk[top].first; --top; } if (!cnt) return; else if (cnt == 1) ret = ret * K % mo; else if (succ && lst == s) { LL buf = 0; for (int i = 1; i <= cnt; ++i) (buf += pw[__gcd(cnt, i)]) %= mo; buf = buf * inv[cnt] % mo; ret = ret * buf % mo; } else ret = ret * C[cnt + K - 1][K - 1] % mo; } void dfs(int x, int f) { dfn[x] = low[x] = ++idx; for (int i = 0; i < (int)nxt[x].size(); ++i) if (nxt[x][i] != f) { int v = nxt[x][i]; stk[++top] = make_pair(x, v); if (!dfn[v]) { dfs(v, x); low[x] = min(low[x], low[v]); if (low[v] >= dfn[x]) chk(x, v); } else if (dfn[v] < dfn[x]) { low[x] = min(low[x], dfn[v]); } else --top; } } int main() { int n, m; scanf("%d%d%d", &n, &m, &K); int mx = m + K; for (int i = 0; i <= mx; ++i) C[i][0] = 1; for (int i = 1; i <= mx; ++i) for (int j = 1; j <= i; ++j) { C[i][j] = C[i - 1][j - 1] + C[i - 1][j]; if (C[i][j] >= mo) C[i][j] -= mo; } pw[0] = inv[0] = 1; inv[1] = 1; for (int i = 1; i <= m; ++i) pw[i] = 1LL * pw[i - 1] * K % mo; for (int i = 2; i <= m; ++i) inv[i] = 1LL * (mo - (mo / i)) * inv[mo % i] % mo; for (int i = 1; i <= m; ++i) { int u, v; scanf("%d%d", &u, &v); nxt[u].push_back(v); nxt[v].push_back(u); } for (int i = 1; i <= n; ++i) if (!dfn[i]) dfs(i, 0); return printf("%lld\n", ret), 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Painting Graphs with AtCoDeer |
User | frank_c1 |
Language | C++14 (GCC 5.4.1) |
Score | 1300 |
Code Size | 2021 Byte |
Status | AC |
Exec Time | 2 ms |
Memory | 384 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:52: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:62:34: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] int u, v; scanf("%d%d", &u, &v); nxt[u].push_back(v); nxt[v].push_back(u); ^
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 | 1 ms | 256 KB |
0_001.txt | AC | 1 ms | 256 KB |
0_002.txt | AC | 1 ms | 256 KB |
1_003.txt | AC | 1 ms | 256 KB |
1_004.txt | AC | 2 ms | 384 KB |
1_005.txt | AC | 2 ms | 384 KB |
1_006.txt | AC | 2 ms | 384 KB |
1_007.txt | AC | 1 ms | 256 KB |
1_008.txt | AC | 1 ms | 256 KB |
1_009.txt | AC | 1 ms | 256 KB |
1_010.txt | AC | 1 ms | 256 KB |
1_011.txt | AC | 1 ms | 256 KB |
1_012.txt | AC | 2 ms | 384 KB |
1_013.txt | AC | 1 ms | 384 KB |
1_014.txt | AC | 2 ms | 384 KB |
1_015.txt | AC | 2 ms | 384 KB |
1_016.txt | AC | 1 ms | 384 KB |
1_017.txt | AC | 2 ms | 384 KB |
1_018.txt | AC | 1 ms | 384 KB |
1_019.txt | AC | 2 ms | 384 KB |
1_020.txt | AC | 2 ms | 384 KB |
1_021.txt | AC | 2 ms | 384 KB |
1_022.txt | AC | 2 ms | 384 KB |
1_023.txt | AC | 2 ms | 384 KB |
1_024.txt | AC | 1 ms | 384 KB |
1_025.txt | AC | 1 ms | 384 KB |
1_026.txt | AC | 1 ms | 384 KB |
1_027.txt | AC | 2 ms | 384 KB |
1_028.txt | AC | 1 ms | 256 KB |
1_029.txt | AC | 1 ms | 256 KB |
1_030.txt | AC | 1 ms | 256 KB |
1_031.txt | AC | 1 ms | 384 KB |
1_032.txt | AC | 1 ms | 256 KB |
1_033.txt | AC | 1 ms | 256 KB |
1_034.txt | AC | 1 ms | 256 KB |
1_035.txt | AC | 1 ms | 384 KB |
1_036.txt | AC | 1 ms | 384 KB |
1_037.txt | AC | 1 ms | 384 KB |
1_038.txt | AC | 1 ms | 384 KB |
1_039.txt | AC | 1 ms | 384 KB |
1_040.txt | AC | 1 ms | 256 KB |
1_041.txt | AC | 1 ms | 256 KB |
1_042.txt | AC | 1 ms | 256 KB |
1_043.txt | AC | 1 ms | 384 KB |
1_044.txt | AC | 1 ms | 256 KB |
1_045.txt | AC | 1 ms | 384 KB |
1_046.txt | AC | 1 ms | 384 KB |
1_047.txt | AC | 2 ms | 384 KB |
1_048.txt | AC | 1 ms | 384 KB |
1_049.txt | AC | 1 ms | 384 KB |
1_050.txt | AC | 2 ms | 384 KB |
1_051.txt | AC | 2 ms | 384 KB |
1_052.txt | AC | 1 ms | 256 KB |
1_053.txt | AC | 1 ms | 256 KB |
1_054.txt | AC | 1 ms | 256 KB |
1_055.txt | AC | 1 ms | 384 KB |
1_056.txt | AC | 1 ms | 256 KB |
1_057.txt | AC | 1 ms | 256 KB |
1_058.txt | AC | 1 ms | 256 KB |
1_059.txt | AC | 2 ms | 384 KB |
1_060.txt | AC | 1 ms | 384 KB |
1_061.txt | AC | 1 ms | 384 KB |
1_062.txt | AC | 1 ms | 384 KB |
1_063.txt | AC | 2 ms | 384 KB |