結果

問題 No.1451 集団登校
ユーザー H3PO4H3PO4
提出日時 2022-06-05 08:55:12
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 664 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 81,648 KB
実行使用メモリ 123,772 KB
最終ジャッジ日時 2023-10-21 03:03:44
合計ジャッジ時間 6,534 ms
ジャッジサーバーID
(参考情報)
judge13 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,468 KB
testcase_01 AC 34 ms
53,468 KB
testcase_02 AC 37 ms
53,468 KB
testcase_03 AC 38 ms
53,468 KB
testcase_04 AC 36 ms
53,468 KB
testcase_05 AC 35 ms
53,468 KB
testcase_06 AC 41 ms
53,468 KB
testcase_07 AC 34 ms
53,468 KB
testcase_08 AC 255 ms
123,772 KB
testcase_09 AC 34 ms
53,488 KB
testcase_10 AC 165 ms
106,192 KB
testcase_11 AC 100 ms
106,272 KB
testcase_12 AC 165 ms
102,796 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 77 ms
93,160 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 AC 159 ms
105,940 KB
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
権限があれば一括ダウンロードができます

ソースコード

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 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] = {}
print(*ans, sep="\n")
0