Submission #1646654
Source Code Expand
#include <cstdio> #include <algorithm> #include <cstring> #include <vector> using namespace std; const int MAX_N = 1005, MOD = 1000000007; typedef long long i64; typedef pair<int, int> pii; class Edge { public: int nxt, to; } e[MAX_N << 1]; int head[MAX_N], cnt, C[MAX_N][MAX_N]; void addedge(int u, int v) { e[++cnt] = (Edge){head[u], v}, head[u] = cnt; e[++cnt] = (Edge){head[v], u}, head[v] = cnt; } int N, M, K, dfn[MAX_N], low[MAX_N], dfs_clock; int st[MAX_N], top, bcc_cnt; vector<int> block[MAX_N]; pii edge[MAX_N]; void find_bcc(int u, int v) { dfn[u] = ++dfs_clock, low[u] = dfn[u]; int temp; for (int i = head[u]; i; i = e[i].nxt) if (!dfn[e[i].to]) { temp = top, st[++top] = (i + 1) / 2; find_bcc(e[i].to, u), low[u] = min(low[u], low[e[i].to]); if (low[e[i].to] >= dfn[u]) { ++bcc_cnt; while (top > temp) block[bcc_cnt].push_back(st[top--]); } } else if (e[i].to != v && dfn[e[i].to] < dfn[u]) { low[u] = min(low[u], dfn[e[i].to]); st[++top] = (i + 1) / 2; } } int fa[MAX_N]; int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); } i64 fpm(i64 x, i64 y) { i64 res = 1; while (y) { if (y & 1) res = res * x % MOD; x = x * x % MOD; y >>= 1; } return res; } i64 work(vector<int> &v) { for (int i = 1; i <= N; ++i) fa[i] = i; int num = 0, n = v.size(); for (int x : v) { int u = find(edge[x].first), v = find(edge[x].second); if (u == v) num++; else fa[u] = v; } if (num == 0) return K; else if (num == 1) { i64 res = 0; for (int i = 1; i <= n; ++i) res = (res + fpm(K, __gcd(i, n))) % MOD; res = res * fpm(n, MOD - 2) % MOD; return res; } else { return C[n + K - 1][K - 1]; } } int main() { scanf("%d%d%d", &N, &M, &K); for (int i = 0; i < MAX_N; ++i) { C[i][0] = 1; for (int j = 1; j <= i; ++j) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD; } for (int i = 1, u, v; i <= M; ++i) { scanf("%d%d", &u, &v); addedge(u, v); edge[i] = make_pair(u, v); } for (int i = 1; i <= N; ++i) if (!dfn[i]) find_bcc(i, 0); i64 res = 1; for (int i = 1; i <= bcc_cnt; ++i) res = res * work(block[i]) % MOD; printf("%lld\n", res); return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Painting Graphs with AtCoDeer |
User | kiiiiii |
Language | C++14 (GCC 5.4.1) |
Score | 1300 |
Code Size | 2390 Byte |
Status | AC |
Exec Time | 4 ms |
Memory | 4224 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:90:30: 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:99:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d", &u, &v); ^
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 | 4 ms | 4224 KB |
0_001.txt | AC | 4 ms | 4224 KB |
0_002.txt | AC | 4 ms | 4224 KB |
1_003.txt | AC | 4 ms | 4224 KB |
1_004.txt | AC | 4 ms | 4224 KB |
1_005.txt | AC | 4 ms | 4224 KB |
1_006.txt | AC | 4 ms | 4224 KB |
1_007.txt | AC | 4 ms | 4224 KB |
1_008.txt | AC | 4 ms | 4224 KB |
1_009.txt | AC | 4 ms | 4224 KB |
1_010.txt | AC | 4 ms | 4224 KB |
1_011.txt | AC | 4 ms | 4224 KB |
1_012.txt | AC | 4 ms | 4224 KB |
1_013.txt | AC | 4 ms | 4224 KB |
1_014.txt | AC | 4 ms | 4224 KB |
1_015.txt | AC | 4 ms | 4224 KB |
1_016.txt | AC | 4 ms | 4224 KB |
1_017.txt | AC | 4 ms | 4224 KB |
1_018.txt | AC | 4 ms | 4224 KB |
1_019.txt | AC | 4 ms | 4224 KB |
1_020.txt | AC | 4 ms | 4224 KB |
1_021.txt | AC | 4 ms | 4224 KB |
1_022.txt | AC | 4 ms | 4224 KB |
1_023.txt | AC | 4 ms | 4224 KB |
1_024.txt | AC | 4 ms | 4224 KB |
1_025.txt | AC | 4 ms | 4224 KB |
1_026.txt | AC | 4 ms | 4224 KB |
1_027.txt | AC | 4 ms | 4224 KB |
1_028.txt | AC | 4 ms | 4224 KB |
1_029.txt | AC | 4 ms | 4224 KB |
1_030.txt | AC | 4 ms | 4224 KB |
1_031.txt | AC | 4 ms | 4224 KB |
1_032.txt | AC | 4 ms | 4224 KB |
1_033.txt | AC | 4 ms | 4224 KB |
1_034.txt | AC | 4 ms | 4224 KB |
1_035.txt | AC | 4 ms | 4224 KB |
1_036.txt | AC | 4 ms | 4224 KB |
1_037.txt | AC | 4 ms | 4224 KB |
1_038.txt | AC | 4 ms | 4224 KB |
1_039.txt | AC | 4 ms | 4224 KB |
1_040.txt | AC | 4 ms | 4224 KB |
1_041.txt | AC | 4 ms | 4224 KB |
1_042.txt | AC | 4 ms | 4224 KB |
1_043.txt | AC | 4 ms | 4224 KB |
1_044.txt | AC | 4 ms | 4224 KB |
1_045.txt | AC | 4 ms | 4224 KB |
1_046.txt | AC | 4 ms | 4224 KB |
1_047.txt | AC | 4 ms | 4224 KB |
1_048.txt | AC | 4 ms | 4224 KB |
1_049.txt | AC | 4 ms | 4224 KB |
1_050.txt | AC | 4 ms | 4224 KB |
1_051.txt | AC | 4 ms | 4224 KB |
1_052.txt | AC | 4 ms | 4224 KB |
1_053.txt | AC | 4 ms | 4224 KB |
1_054.txt | AC | 4 ms | 4224 KB |
1_055.txt | AC | 4 ms | 4224 KB |
1_056.txt | AC | 4 ms | 4224 KB |
1_057.txt | AC | 4 ms | 4224 KB |
1_058.txt | AC | 4 ms | 4224 KB |
1_059.txt | AC | 4 ms | 4224 KB |
1_060.txt | AC | 4 ms | 4224 KB |
1_061.txt | AC | 4 ms | 4224 KB |
1_062.txt | AC | 4 ms | 4224 KB |
1_063.txt | AC | 4 ms | 4224 KB |