Submission #948415
Source Code Expand
#include <bits/stdc++.h> /* -------------------------------- Template -------------------------------- */ #define REP(i,n) for(int i=0;i<(int)(n);i++) #define ALL(x) (x).begin(),(x).end() using namespace std; using ll = long long; using ld = long double; template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); } template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); } template<typename T> T inf() { assert(false); } template<> constexpr int inf<int>() { return 1e9; } template<> constexpr ll inf<ll>() { return 1e18; } template<> constexpr ld inf<ld>() { return 1e30; } struct yes_no : numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } }; /* -------------------------------- Library -------------------------------- */ struct Edge{ int src, dest; bool operator < (const Edge &rhs) const { return make_pair(src, dest) < make_pair(rhs.src, rhs.dest); } }; typedef vector<Edge> Edges; typedef vector<Edges> Graph; set<int> art; vector<set<Edge> > connect; vector<Edge> st; vector<int> order, low; int cnt; void artDfs(const Graph &g, int from, int parent) { low[from] = order[from] = cnt++; for (Edge e : g[from]) { int to = e.dest; if (to != parent && order[to] < order[from]) st.push_back(e); if (order[to] == -1) { artDfs(g, to, from); low[from] = min(low[from], low[to]); if ((order[from] == 0 && order[to] != 1) || (order[from] != 0 && low[to] >= order[from])) art.insert(from); if (low[to] >= order[from]) { connect.push_back(set<Edge>()); while (true) { Edge edge = st.back(); st.pop_back(); connect.back().insert(edge); if (edge.src == from && edge.dest == to) break; } } } else { low[from] = min(low[from], order[to]); } } } set<int> articulationPoints(const Graph &g) { const int n = g.size(); art.clear(); connect.clear(); st.clear(); order.assign(n, -1); low.assign(n, -1); for (int i = 0; i < n; i++) { if (order[i] != -1) continue; cnt = 0; artDfs(g, i, i); } return art; } const int mod = 1000000007; struct Mod { int n; Mod () : n(0) {;} Mod (int m) : n(m) { if (n >= mod) n %= mod; else if (n < 0) n = (n % mod + mod) % mod; } operator int() { return n; } }; bool operator==(Mod a, Mod b) { return a.n == b.n; } Mod operator+=(Mod &a, Mod b) { a.n += b.n; if (a.n >= mod) a.n -= mod; return a; } Mod operator-=(Mod &a, Mod b) { a.n -= b.n; if (a.n < 0) a.n += mod; return a; } Mod operator*=(Mod &a, Mod b) { a.n = ((long long)a.n * b.n) % mod; return a; } Mod operator+(Mod a, Mod b) { return a += b; } Mod operator-(Mod a, Mod b) { return a -= b; } Mod operator*(Mod a, Mod b) { return a *= b; } Mod operator^(Mod a, int n) { if (n == 0) return Mod(1); Mod res = (a * a) ^ (n / 2); if (n % 2) res = res * a; return res; } ll inv(ll a, ll p) { return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p); } Mod operator/(Mod a, Mod b) { return a * Mod(inv(b, mod)); } #define MAX_N 1024000 Mod fact[MAX_N], factinv[MAX_N]; void init() { fact[0] = Mod(1); factinv[0] = 1; REP(i,MAX_N-1) { fact[i+1] = fact[i] * Mod(i+1); factinv[i+1] = factinv[i] / Mod(i+1); } } Mod comb(int a, int b) { return fact[a] * factinv[b] * factinv[a-b]; } /* ---------------------------------- Main ---------------------------------- */ int main() { locale loc(locale(), new yes_no); cout << boolalpha; cout.imbue(loc); init(); int N, M, K; cin >> N >> M >> K; Graph g(N); REP(i,M) { int a, b; cin >> a >> b; --a; --b; g[a].push_back((Edge){a, b}); g[b].push_back((Edge){b, a}); } articulationPoints(g); Mod res = 1; for (auto es: connect) { vector<int> vs; for (auto e: es) { vs.push_back(e.src); vs.push_back(e.dest); } sort(ALL(vs)); auto it = unique(ALL(vs)); int n = it - begin(vs); int m = es.size(); if (n != m) { res *= comb(K - 1 + m, m); continue; } Mod sum = 0; for (int i = 1; i <= n; ++i) { int g = __gcd(i, n); sum += Mod(K) ^ g; } res *= sum / Mod(n); } cout << res << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Painting Graphs with AtCoDeer |
User | asi1024 |
Language | C++14 (GCC 5.4.1) |
Score | 1300 |
Code Size | 4431 Byte |
Status | AC |
Exec Time | 356 ms |
Memory | 8320 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 | 355 ms | 8192 KB |
0_001.txt | AC | 355 ms | 8192 KB |
0_002.txt | AC | 355 ms | 8192 KB |
1_003.txt | AC | 355 ms | 8192 KB |
1_004.txt | AC | 355 ms | 8192 KB |
1_005.txt | AC | 355 ms | 8320 KB |
1_006.txt | AC | 355 ms | 8320 KB |
1_007.txt | AC | 355 ms | 8192 KB |
1_008.txt | AC | 355 ms | 8192 KB |
1_009.txt | AC | 355 ms | 8320 KB |
1_010.txt | AC | 356 ms | 8320 KB |
1_011.txt | AC | 355 ms | 8192 KB |
1_012.txt | AC | 355 ms | 8320 KB |
1_013.txt | AC | 355 ms | 8320 KB |
1_014.txt | AC | 355 ms | 8192 KB |
1_015.txt | AC | 355 ms | 8320 KB |
1_016.txt | AC | 355 ms | 8192 KB |
1_017.txt | AC | 355 ms | 8320 KB |
1_018.txt | AC | 355 ms | 8192 KB |
1_019.txt | AC | 355 ms | 8320 KB |
1_020.txt | AC | 355 ms | 8320 KB |
1_021.txt | AC | 355 ms | 8192 KB |
1_022.txt | AC | 355 ms | 8192 KB |
1_023.txt | AC | 355 ms | 8192 KB |
1_024.txt | AC | 355 ms | 8320 KB |
1_025.txt | AC | 355 ms | 8192 KB |
1_026.txt | AC | 355 ms | 8320 KB |
1_027.txt | AC | 354 ms | 8320 KB |
1_028.txt | AC | 355 ms | 8192 KB |
1_029.txt | AC | 355 ms | 8192 KB |
1_030.txt | AC | 355 ms | 8320 KB |
1_031.txt | AC | 355 ms | 8320 KB |
1_032.txt | AC | 355 ms | 8192 KB |
1_033.txt | AC | 355 ms | 8192 KB |
1_034.txt | AC | 355 ms | 8192 KB |
1_035.txt | AC | 355 ms | 8320 KB |
1_036.txt | AC | 355 ms | 8192 KB |
1_037.txt | AC | 355 ms | 8192 KB |
1_038.txt | AC | 355 ms | 8192 KB |
1_039.txt | AC | 355 ms | 8320 KB |
1_040.txt | AC | 355 ms | 8192 KB |
1_041.txt | AC | 355 ms | 8192 KB |
1_042.txt | AC | 355 ms | 8320 KB |
1_043.txt | AC | 355 ms | 8320 KB |
1_044.txt | AC | 355 ms | 8192 KB |
1_045.txt | AC | 355 ms | 8192 KB |
1_046.txt | AC | 355 ms | 8320 KB |
1_047.txt | AC | 355 ms | 8320 KB |
1_048.txt | AC | 355 ms | 8192 KB |
1_049.txt | AC | 355 ms | 8192 KB |
1_050.txt | AC | 355 ms | 8320 KB |
1_051.txt | AC | 355 ms | 8320 KB |
1_052.txt | AC | 355 ms | 8192 KB |
1_053.txt | AC | 355 ms | 8192 KB |
1_054.txt | AC | 355 ms | 8320 KB |
1_055.txt | AC | 355 ms | 8320 KB |
1_056.txt | AC | 355 ms | 8192 KB |
1_057.txt | AC | 355 ms | 8192 KB |
1_058.txt | AC | 355 ms | 8192 KB |
1_059.txt | AC | 355 ms | 8320 KB |
1_060.txt | AC | 355 ms | 8192 KB |
1_061.txt | AC | 355 ms | 8192 KB |
1_062.txt | AC | 355 ms | 8320 KB |
1_063.txt | AC | 355 ms | 8320 KB |