Submission #1680471
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; void main() { auto s = readln.split.map!(to!int); auto N = s[0].to!int; auto M = s[1]; auto edges = new int[][](N); foreach (_; 0..M) { s = readln.split.map!(to!int); edges[s[0]-1] ~= s[1]-1; edges[s[1]-1] ~= s[0]-1; } int[][] groups; bool[] used = new bool[](N); int[] color = new int[](N); color.fill(-1); void dfs1(int n, int g) { if (used[n]) return; used[n] = true; groups[g] ~= n; foreach (m; edges[n]) if (used[n]) dfs1(m, g); } bool dfs2(int n, int c) { if (color[n] != -1) return color[n] == c; color[n] = c; foreach (m; edges[n]) { if (!dfs2(m, c^1)) return false; } return true; } int gn = 0; bool[] is_bi; foreach (i; 0..N) if (!used[i]) {groups ~= (new int[](0)); dfs1(i, gn++);} foreach (g; 0..gn) is_bi ~= dfs2(groups[g][0], g); long ans = 0; long G = groups.length; long one = groups.map!(g => g.length == 1).sum; long bi = is_bi.sum - one; long other = G - one - bi; ans += one * 2 * N - one * one; ans += bi * 2 + other; ans += bi * (bi - 1) * 2; ans += other * (other - 1); ans += other * bi * 2; ans.writeln; }
Submission Info
Submission Time | |
---|---|
Task | C - Squared Graph |
User | nebukuro09 |
Language | D (LDC 0.17.0) |
Score | 800 |
Code Size | 1503 Byte |
Status | AC |
Exec Time | 204 ms |
Memory | 25596 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 800 / 800 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample1.txt, sample2.txt |
All | sample1.txt, sample2.txt, in1.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in2.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in3.txt, in4.txt, in5.txt, in6.txt, in7.txt, in8.txt, in9.txt, sample1.txt, sample2.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
in1.txt | AC | 1 ms | 256 KB |
in10.txt | AC | 26 ms | 7548 KB |
in11.txt | AC | 1 ms | 256 KB |
in12.txt | AC | 64 ms | 10876 KB |
in13.txt | AC | 65 ms | 10620 KB |
in14.txt | AC | 109 ms | 12284 KB |
in15.txt | AC | 32 ms | 6396 KB |
in16.txt | AC | 95 ms | 12284 KB |
in17.txt | AC | 69 ms | 11772 KB |
in18.txt | AC | 151 ms | 16764 KB |
in19.txt | AC | 108 ms | 13948 KB |
in2.txt | AC | 1 ms | 256 KB |
in20.txt | AC | 110 ms | 14204 KB |
in21.txt | AC | 199 ms | 25084 KB |
in22.txt | AC | 173 ms | 20956 KB |
in23.txt | AC | 155 ms | 8700 KB |
in24.txt | AC | 26 ms | 5756 KB |
in25.txt | AC | 201 ms | 25468 KB |
in26.txt | AC | 1 ms | 256 KB |
in27.txt | AC | 2 ms | 508 KB |
in28.txt | AC | 204 ms | 25596 KB |
in3.txt | AC | 1 ms | 256 KB |
in4.txt | AC | 1 ms | 324 KB |
in5.txt | AC | 173 ms | 19708 KB |
in6.txt | AC | 29 ms | 5756 KB |
in7.txt | AC | 30 ms | 6396 KB |
in8.txt | AC | 38 ms | 6012 KB |
in9.txt | AC | 78 ms | 12028 KB |
sample1.txt | AC | 1 ms | 256 KB |
sample2.txt | AC | 1 ms | 256 KB |