結果
問題 | No.317 辺の追加 |
ユーザー |
|
提出日時 | 2017-06-20 16:13:59 |
言語 | D (dmd 2.106.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,241 bytes |
コンパイル時間 | 777 ms |
コンパイル使用メモリ | 104,504 KB |
実行使用メモリ | 13,888 KB |
最終ジャッジ日時 | 2024-06-12 20:20:10 |
合計ジャッジ時間 | 7,187 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
13,888 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 983 ms
6,816 KB |
testcase_03 | AC | 221 ms
6,944 KB |
testcase_04 | TLE | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
ソースコード
import std.algorithm, std.conv, std.range, std.stdio, std.string; const inf = 10 ^^ 6; void main() { auto rd1 = readln.split.to!(size_t[]), n = rd1[0], m = rd1[1]; auto uf = UnionFind!size_t(n); foreach (_; 0..m) { auto rd2 = readln.split.to!(size_t[]), x = rd2[0]-1, y = rd2[1]-1; uf.unite(x, y); } auto si = new int[](n); foreach (i; 0..n) ++si[uf.find(i)]; auto ti = si.filter!"a > 0".array; auto dp = new int[](n+1); dp[] = inf; foreach (t; ti) { foreach_reverse (i; t+1..n+1) dp[i] = min(dp[i], dp[i-t] + 1); dp[t] = 0; } foreach (r; dp[1..$]) writeln(r >= inf ? -1 : r); } struct UnionFind(T) { import std.algorithm, std.range; T[] p; // parent const T s; // sentinel const T n; this(T n) { this.n = n; p = new T[](n); s = n + 1; p[] = s; } T find(T i) { if (p[i] == s) { return i; } else { p[i] = find(p[i]); return p[i]; } } void unite(T i, T j) { auto pi = find(i), pj = find(j); if (pi != pj) p[pj] = pi; } bool isSame(T i, T j) { return find(i) == find(j); } auto groups() { auto g = new T[][](n); foreach (i; 0..n) g[find(i)] ~= i; return g.filter!(l => !l.empty); } }