Submission #3249107
Source Code Expand
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, std.bitmanip; immutable long MOD = 10^^9 + 7; void main() { auto s = readln.split.map!(to!int); auto N = s[0]; auto M = s[1]; auto K = s[2]; auto G = new UndirectedGraph(N); foreach (_; 0..M) { s = readln.split.map!(to!int); G.add_edge(s[0]-1, s[1]-1); } auto bicom = biconnected_decomposition(G); long ans = 1; //foreach (b; bicom) { // b.map!(a => "(" ~ to!string(a[0]+1) ~ ", " ~ to!string(a[1]+1) ~ ")").join(" ").writeln; //} foreach (edges; bicom) { int[] nodes; foreach (e; edges) nodes ~= e[0], nodes ~= e[1]; nodes = nodes.sort().uniq().array; if (edges.length == 1) { ans = ans * K % MOD; } else if (edges.length == nodes.length) { long tmp = 0; foreach (i; 0..nodes.length) { tmp += powmod(K, gcd(nodes.length.to!long, i.to!long), MOD); tmp %= MOD; } tmp = tmp * powmod(nodes.length.to!long, MOD-2, MOD) % MOD; ans = ans * tmp % MOD; } else { ans = ans * comb(K + edges.length.to!int - 1, edges.length.to!int) % MOD; } } ans.writeln; } Tuple!(int, int)[][] biconnected_decomposition(UndirectedGraph g) { Tuple!(int, int)[][] ret; int cnt = 0; Tuple!(int, int)[] stack; auto ord = new int[](g.N); auto low = new int[](g.N); fill(ord, -1); fill(low, -1); void dfs(int n, int p) { ord[n] = cnt; low[n] = cnt; cnt += 1; foreach (m; g.adj[n]) { if (ord[m] == -1) { stack ~= tuple(n, m); dfs(m, n); low[n] = min(low[n], low[m]); if (low[m] >= ord[n]) { Tuple!(int, int)[] bicom; while (bicom.empty || bicom.back != tuple(n, m)) { bicom ~= stack.back; stack.popBack; } ret ~= bicom.dup; } } else if (ord[m] < ord[n] && m != p) { stack ~= tuple(n, m); low[n] = min(low[n], ord[m]); } } } foreach (i; 0..g.N) { if (ord[i] == -1) dfs(i, -1); } return ret; } class UndirectedGraph { int N; int[][] adj; this (int N) { this.N = N; adj = new int[][](N); } void add_edge(int u, int v) { adj[u] ~= v; adj[v] ~= u; } } long powmod(long a, long x, long m) { long ret = 1; while (x) { if (x % 2) ret = ret * a % m; a = a * a % m; x /= 2; } return ret; } long comb(long n, long k) { long ret = 1; foreach (i; 1..n+1) ret = ret * i % MOD; foreach (i; 1..n-k+1) ret = ret * powmod(i, MOD-2, MOD) % MOD; foreach (i; 1..k+1) ret = ret * powmod(i, MOD-2, MOD) % MOD; return ret; }
Submission Info
Submission Time | |
---|---|
Task | F - Painting Graphs with AtCoDeer |
User | nebukuro09 |
Language | D (LDC 0.17.0) |
Score | 1300 |
Code Size | 3224 Byte |
Status | AC |
Exec Time | 2 ms |
Memory | 380 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 | 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 | 1 ms | 256 KB |
1_005.txt | AC | 1 ms | 256 KB |
1_006.txt | AC | 1 ms | 256 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 | 1 ms | 256 KB |
1_013.txt | AC | 1 ms | 256 KB |
1_014.txt | AC | 1 ms | 256 KB |
1_015.txt | AC | 1 ms | 256 KB |
1_016.txt | AC | 1 ms | 256 KB |
1_017.txt | AC | 1 ms | 256 KB |
1_018.txt | AC | 1 ms | 256 KB |
1_019.txt | AC | 1 ms | 256 KB |
1_020.txt | AC | 1 ms | 256 KB |
1_021.txt | AC | 1 ms | 256 KB |
1_022.txt | AC | 1 ms | 256 KB |
1_023.txt | AC | 2 ms | 380 KB |
1_024.txt | AC | 1 ms | 256 KB |
1_025.txt | AC | 1 ms | 256 KB |
1_026.txt | AC | 1 ms | 256 KB |
1_027.txt | AC | 1 ms | 256 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 | 256 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 | 256 KB |
1_036.txt | AC | 1 ms | 256 KB |
1_037.txt | AC | 1 ms | 256 KB |
1_038.txt | AC | 1 ms | 256 KB |
1_039.txt | AC | 1 ms | 256 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 | 256 KB |
1_044.txt | AC | 1 ms | 256 KB |
1_045.txt | AC | 1 ms | 256 KB |
1_046.txt | AC | 1 ms | 256 KB |
1_047.txt | AC | 1 ms | 256 KB |
1_048.txt | AC | 1 ms | 256 KB |
1_049.txt | AC | 1 ms | 256 KB |
1_050.txt | AC | 1 ms | 256 KB |
1_051.txt | AC | 1 ms | 256 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 | 256 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 | 1 ms | 256 KB |
1_060.txt | AC | 1 ms | 256 KB |
1_061.txt | AC | 1 ms | 256 KB |
1_062.txt | AC | 1 ms | 256 KB |
1_063.txt | AC | 1 ms | 256 KB |