結果
問題 | No.556 仁義なきサルたち |
ユーザー | 6soukiti29 |
提出日時 | 2017-08-12 00:18:28 |
言語 | Nim (2.0.2) |
結果 |
AC
|
実行時間 | 21 ms / 2,000 ms |
コード長 | 1,256 bytes |
コンパイル時間 | 3,075 ms |
コンパイル使用メモリ | 67,996 KB |
実行使用メモリ | 4,384 KB |
最終ジャッジ日時 | 2023-09-12 14:04:09 |
合計ジャッジ時間 | 4,223 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 1 ms
4,380 KB |
testcase_04 | AC | 2 ms
4,380 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 2 ms
4,380 KB |
testcase_07 | AC | 2 ms
4,380 KB |
testcase_08 | AC | 3 ms
4,380 KB |
testcase_09 | AC | 3 ms
4,380 KB |
testcase_10 | AC | 3 ms
4,380 KB |
testcase_11 | AC | 3 ms
4,384 KB |
testcase_12 | AC | 3 ms
4,380 KB |
testcase_13 | AC | 8 ms
4,380 KB |
testcase_14 | AC | 10 ms
4,380 KB |
testcase_15 | AC | 11 ms
4,380 KB |
testcase_16 | AC | 17 ms
4,376 KB |
testcase_17 | AC | 19 ms
4,380 KB |
testcase_18 | AC | 21 ms
4,376 KB |
testcase_19 | AC | 20 ms
4,376 KB |
testcase_20 | AC | 21 ms
4,376 KB |
testcase_21 | AC | 20 ms
4,380 KB |
ソースコード
import sequtils,strutils type unionfindtree[I : static[int]] = array[I,int] var N,M : int (N, M) = stdin.readline.split.map(parseInt) var num = newSeqWith(N + 1,1) ut : unionfindtree[10001] a,b : int proc initUT[I](i : int):unionfindtree[I] = unionfindtree[i] proc find(U : unionfindtree; a : int, b :int): bool= var s = a t = b while s != U[s]: s = U[s] while t != U[t]: t = U[t] return s == t proc union(U : var unionfindtree; a : int ; b : int)= if U.find(a,b): return var s = a t = b t2 : int while s != U[s]: s = U[s] while t != U[t]: t = U[t] if num[s] < num[t]: U[s] = t num[t] += num[s] num[s] = 0 if num[t] < num[s]: U[t] = s num[s] += num[t] num[t] = 0 if num[t] == num[s]: if t < s: (t, s) = (s, t) U[t] = s num[s] += num[t] num[t] = 0 proc root(U : unionfindtree, a :int):int= var s = a while s != U[s]: s = U[s] return s for i in 1..N: ut[i] = i for m in 1..M: (a, b) = stdin.readline.split.map(parseInt) ut.union(a,b) for i in 1..N: echo ut.root(i)