Submission #932188
Source Code Expand
#include <iostream> #include <fstream> #include <set> #include <map> #include <string> #include <vector> #include <bitset> #include <algorithm> #include <cstring> #include <cstdlib> #include <cmath> #include <cassert> #include <queue> #define mp make_pair #define pb push_back typedef long long ll; typedef long double ld; using namespace std; const ll MOD = 1e9 + 7; int n, m, k; vector<int> eds[100]; int h[100]; int was[100]; int was1[100]; int cl[100]; vector<pair<int, int> > ed2; ll dp1[120]; ll cnk[220][220]; ll pw(ll a, ll b) { ll ans = 1; while (b) { while (!(b & 1)) b >>= 1, a = (a * a) % MOD; ans = (ans * a) % MOD; --b; } return ans; } void dfs1(int v, int hh = 0) { h[v] = hh; was1[v] = 1; for (int u: eds[v]) if (!was1[u]) dfs1(u, hh + 1); } ll gans = 1; void upd(vector<int> vv) { int cnt = 0; memset(cl, 0, sizeof(cl)); for (int i: vv) cl[i] = 1; for (pair<int, int> i: ed2) { if (cl[i.first] && cl[i.second]) ++cnt; } ll ans = 0; if (cnt == (int)vv.size()) { for (int j = 1; j <= cnt; ++j) if (cnt % j == 0) ans = (ans + dp1[j]) % MOD; } else { ans = cnk[cnt + k - 1][k - 1]; } gans = (gans * ans) % MOD; } pair<int, vector<int> > dfs2(int v) { was[v] = 1; vector<int> ans; ans.push_back(v); int mx = h[v]; for (int u: eds[v]) { if (!was[u]) { pair<int, vector<int> > tmp = dfs2(u); if (tmp.first < h[v]) { mx = min(mx, tmp.first); for (int x: tmp.second) ans.push_back(x); } else if (tmp.first == h[v]) { tmp.second.push_back(v); upd(tmp.second); } else { gans = (gans * k) % MOD; } } else { mx = min(mx, h[u]); } } return make_pair(mx, ans); } int main() { cin >> n >> m >> k; dp1[0] = 0; for (int i = 1; i <= n; ++i) { dp1[i] = 1; for (int j = 0; j < i; ++j) dp1[i] = (dp1[i] * k) % MOD; for (int j = 1; j < i; ++j) if (i % j == 0) dp1[i] = (dp1[i] - dp1[j] + MOD) % MOD; } for (int i = 1; i <= n; ++i) { dp1[i] = (dp1[i] * pw(i, MOD - 2)) % MOD; } for (int i = 0; i < 220; ++i) for (int j = 0; j < 220; ++j) { if (i == j || j == 0) cnk[i][j] = 1; else if (j > i) cnk[i][j] = 0; else cnk[i][j] = (cnk[i - 1][j] + cnk[i - 1][j - 1]) % MOD; } for (int i = 0; i < m; ++i) { int a, b; cin >> a >> b; --a, --b; eds[a].push_back(b); eds[b].push_back(a); ed2.push_back(make_pair(a, b)); } for (int i = 0; i < n; ++i) { if (was1[i]) continue; dfs1(i); auto x = dfs2(i); if ((int)x.second.size() != 1) { upd(x.second); } } cout << gans << "\n"; return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Painting Graphs with AtCoDeer |
User | LHiC |
Language | C++14 (GCC 5.4.1) |
Score | 1300 |
Code Size | 2728 Byte |
Status | AC |
Exec Time | 3 ms |
Memory | 768 KB |
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 | 640 KB |
0_001.txt | AC | 3 ms | 640 KB |
0_002.txt | AC | 3 ms | 640 KB |
1_003.txt | AC | 3 ms | 640 KB |
1_004.txt | AC | 3 ms | 640 KB |
1_005.txt | AC | 3 ms | 640 KB |
1_006.txt | AC | 3 ms | 640 KB |
1_007.txt | AC | 3 ms | 640 KB |
1_008.txt | AC | 3 ms | 640 KB |
1_009.txt | AC | 3 ms | 640 KB |
1_010.txt | AC | 3 ms | 640 KB |
1_011.txt | AC | 3 ms | 640 KB |
1_012.txt | AC | 3 ms | 640 KB |
1_013.txt | AC | 3 ms | 640 KB |
1_014.txt | AC | 3 ms | 640 KB |
1_015.txt | AC | 3 ms | 640 KB |
1_016.txt | AC | 3 ms | 640 KB |
1_017.txt | AC | 3 ms | 640 KB |
1_018.txt | AC | 3 ms | 640 KB |
1_019.txt | AC | 3 ms | 640 KB |
1_020.txt | AC | 3 ms | 640 KB |
1_021.txt | AC | 3 ms | 640 KB |
1_022.txt | AC | 3 ms | 640 KB |
1_023.txt | AC | 3 ms | 640 KB |
1_024.txt | AC | 3 ms | 640 KB |
1_025.txt | AC | 3 ms | 640 KB |
1_026.txt | AC | 3 ms | 640 KB |
1_027.txt | AC | 3 ms | 640 KB |
1_028.txt | AC | 3 ms | 640 KB |
1_029.txt | AC | 3 ms | 640 KB |
1_030.txt | AC | 3 ms | 640 KB |
1_031.txt | AC | 3 ms | 640 KB |
1_032.txt | AC | 3 ms | 640 KB |
1_033.txt | AC | 3 ms | 640 KB |
1_034.txt | AC | 3 ms | 640 KB |
1_035.txt | AC | 3 ms | 640 KB |
1_036.txt | AC | 3 ms | 640 KB |
1_037.txt | AC | 3 ms | 640 KB |
1_038.txt | AC | 3 ms | 640 KB |
1_039.txt | AC | 3 ms | 640 KB |
1_040.txt | AC | 3 ms | 640 KB |
1_041.txt | AC | 3 ms | 640 KB |
1_042.txt | AC | 3 ms | 640 KB |
1_043.txt | AC | 3 ms | 640 KB |
1_044.txt | AC | 3 ms | 640 KB |
1_045.txt | AC | 3 ms | 640 KB |
1_046.txt | AC | 3 ms | 640 KB |
1_047.txt | AC | 3 ms | 640 KB |
1_048.txt | AC | 3 ms | 640 KB |
1_049.txt | AC | 3 ms | 640 KB |
1_050.txt | AC | 3 ms | 640 KB |
1_051.txt | AC | 3 ms | 640 KB |
1_052.txt | AC | 3 ms | 640 KB |
1_053.txt | AC | 3 ms | 640 KB |
1_054.txt | AC | 3 ms | 640 KB |
1_055.txt | AC | 3 ms | 640 KB |
1_056.txt | AC | 3 ms | 640 KB |
1_057.txt | AC | 3 ms | 640 KB |
1_058.txt | AC | 3 ms | 640 KB |
1_059.txt | AC | 3 ms | 640 KB |
1_060.txt | AC | 3 ms | 640 KB |
1_061.txt | AC | 3 ms | 768 KB |
1_062.txt | AC | 3 ms | 640 KB |
1_063.txt | AC | 3 ms | 640 KB |