結果
問題 | No.1451 集団登校 |
ユーザー | qib |
提出日時 | 2023-01-27 16:36:57 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 677 bytes |
コンパイル時間 | 329 ms |
コンパイル使用メモリ | 86,960 KB |
実行使用メモリ | 188,172 KB |
最終ジャッジ日時 | 2023-09-10 11:05:33 |
合計ジャッジ時間 | 7,698 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 71 ms
75,512 KB |
testcase_01 | WA | - |
testcase_02 | AC | 71 ms
71,064 KB |
testcase_03 | AC | 71 ms
71,248 KB |
testcase_04 | WA | - |
testcase_05 | AC | 70 ms
71,008 KB |
testcase_06 | WA | - |
testcase_07 | AC | 72 ms
71,300 KB |
testcase_08 | AC | 205 ms
94,392 KB |
testcase_09 | AC | 70 ms
71,264 KB |
testcase_10 | WA | - |
testcase_11 | AC | 110 ms
89,096 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | TLE | - |
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 | -- | - |
ソースコード
MOD = 10 ** 9 + 7 n, m = map(int, input().split()) inv2 = pow(2, MOD - 2, MOD) ans = [1 for _ in range(n)] grp = [[i] for i in range(n)] par = [i for i in range(n)] for _ in range(m): a, b = map(int, input().split()) a = par[a - 1] b = par[b - 1] if a != b: la = len(grp[a]) lb = len(grp[b]) if la > lb: la, lb = lb, la if la == lb: while len(grp[a]) > 0: v = grp[a].pop() par[v] = b grp[b].append(v) for v in grp[b]: ans[v] = (ans[v] * inv2) % MOD else: while len(grp[a]) > 0: v = grp[a].pop() par[v] = b grp[b].append(v) ans[v] = 0 print(*ans, sep="\n")