結果

問題 No.1451 集団登校
ユーザー 👑 rin204rin204
提出日時 2022-04-15 15:32:45
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 791 bytes
コンパイル時間 1,897 ms
コンパイル使用メモリ 86,628 KB
実行使用メモリ 93,960 KB
最終ジャッジ日時 2023-08-26 05:46:50
合計ジャッジ時間 7,826 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
70,936 KB
testcase_01 AC 61 ms
71,212 KB
testcase_02 AC 60 ms
71,140 KB
testcase_03 AC 65 ms
71,136 KB
testcase_04 AC 65 ms
71,292 KB
testcase_05 AC 64 ms
71,000 KB
testcase_06 AC 65 ms
71,328 KB
testcase_07 AC 65 ms
71,420 KB
testcase_08 AC 192 ms
93,960 KB
testcase_09 AC 63 ms
71,256 KB
testcase_10 WA -
testcase_11 AC 94 ms
89,276 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 89 ms
83,968 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10 ** 9 + 7

n, m = map(int, input().split())
leader = [[i] for i in range(n)]
parent = [-1] * n
ans = [1] * n
inv = pow(2, MOD - 2, MOD)
def find(x):
    if parent[x] < 0:
        return x
    parent[x] = find(parent[x])
    return parent[x]

def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return

    if parent[x] > parent[y]:
        x, y = y, x
        leader[x], leader[y] = leader[y], leader[x]
    
    if parent[x] == parent[y]:
        leader[x] += leader[y]
        for i in leader[x]:
            ans[i] *= inv
            ans[i] %= MOD
    else:
        for i in leader[y]:
            ans[i] = 0

    parent[x] += parent[y]
    parent[y] = x

for _ in range(m):
    a, b = map(int, input().split())
    unite(a - 1, b - 1)


print(*ans, sep="\n")
0