結果

問題 No.1451 集団登校
ユーザー 👑 rin204rin204
提出日時 2022-04-15 15:21:17
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 758 bytes
コンパイル時間 587 ms
コンパイル使用メモリ 87,072 KB
実行使用メモリ 94,352 KB
最終ジャッジ日時 2023-08-26 05:42:11
合計ジャッジ時間 9,228 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,228 KB
testcase_01 AC 74 ms
71,096 KB
testcase_02 AC 70 ms
71,348 KB
testcase_03 AC 69 ms
71,236 KB
testcase_04 AC 71 ms
71,400 KB
testcase_05 AC 71 ms
71,340 KB
testcase_06 AC 70 ms
71,100 KB
testcase_07 AC 70 ms
71,360 KB
testcase_08 AC 197 ms
94,012 KB
testcase_09 AC 70 ms
71,348 KB
testcase_10 WA -
testcase_11 AC 185 ms
89,032 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 142 ms
84,528 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

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]
    elif parent[x] == parent[y]:
        leader[x] += leader[y]

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

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

ans = [0] * n
for i in range(n):
    if parent[i] < 0:
        x = pow(len(leader[i]), MOD - 2, MOD)
        for j in leader[i]:
            ans[j] = x
print(*ans, sep="\n")
0