結果

問題 No.1451 集団登校
ユーザー H3PO4H3PO4
提出日時 2022-06-05 08:57:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 337 ms / 2,000 ms
コード長 701 bytes
コンパイル時間 203 ms
コンパイル使用メモリ 81,880 KB
実行使用メモリ 124,220 KB
最終ジャッジ日時 2023-10-21 03:03:51
合計ジャッジ時間 6,655 ms
ジャッジサーバーID
(参考情報)
judge9 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,348 KB
testcase_01 AC 38 ms
53,348 KB
testcase_02 AC 37 ms
53,348 KB
testcase_03 AC 38 ms
53,348 KB
testcase_04 AC 38 ms
53,348 KB
testcase_05 AC 39 ms
53,348 KB
testcase_06 AC 39 ms
53,348 KB
testcase_07 AC 40 ms
53,348 KB
testcase_08 AC 290 ms
124,220 KB
testcase_09 AC 40 ms
53,408 KB
testcase_10 AC 203 ms
106,284 KB
testcase_11 AC 113 ms
106,104 KB
testcase_12 AC 201 ms
102,996 KB
testcase_13 AC 294 ms
112,972 KB
testcase_14 AC 337 ms
108,516 KB
testcase_15 AC 223 ms
97,832 KB
testcase_16 AC 276 ms
108,740 KB
testcase_17 AC 159 ms
77,228 KB
testcase_18 AC 176 ms
88,604 KB
testcase_19 AC 86 ms
92,988 KB
testcase_20 AC 335 ms
109,156 KB
testcase_21 AC 127 ms
76,244 KB
testcase_22 AC 141 ms
81,104 KB
testcase_23 AC 86 ms
75,752 KB
testcase_24 AC 186 ms
105,760 KB
testcase_25 AC 213 ms
96,956 KB
testcase_26 AC 271 ms
107,964 KB
testcase_27 AC 248 ms
92,500 KB
testcase_28 AC 166 ms
85,128 KB
testcase_29 AC 220 ms
96,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())
MOD = 10 ** 9 + 7
i2 = pow(2, MOD - 2, MOD)
ans = [1] * N
st = [{i} for i in range(N)]
root = list(range(N))
for _ in range(M):
    a, b = (int(x) - 1 for x in input().split())
    ra = root[a]
    rb = root[b]
    if ra == rb:
        continue
    if len(st[ra]) == len(st[rb]):
        for x in st[ra]:
            ans[x] *= i2
            ans[x] %= MOD
        for x in st[rb]:
            ans[x] *= i2
            ans[x] %= MOD
            root[x] = ra
    else:
        if len(st[ra]) < len(st[rb]):
            ra, rb = rb, ra
        for x in st[rb]:
            ans[x] = 0
            root[x] = ra
    st[ra] |= st[rb]
    st[rb] = set()
print(*ans, sep="\n")
0