結果

問題 No.1451 集団登校
ユーザー shiomusubi496shiomusubi496
提出日時 2021-03-25 10:58:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 768 ms / 2,000 ms
コード長 679 bytes
コンパイル時間 77 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 47,444 KB
最終ジャッジ日時 2024-05-05 07:42:06
合計ジャッジ時間 8,553 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
10,752 KB
testcase_01 AC 25 ms
10,752 KB
testcase_02 AC 26 ms
10,880 KB
testcase_03 AC 25 ms
10,880 KB
testcase_04 AC 25 ms
10,752 KB
testcase_05 AC 25 ms
10,752 KB
testcase_06 AC 29 ms
10,752 KB
testcase_07 AC 27 ms
10,752 KB
testcase_08 AC 768 ms
47,444 KB
testcase_09 AC 26 ms
10,752 KB
testcase_10 AC 278 ms
41,600 KB
testcase_11 AC 172 ms
41,472 KB
testcase_12 AC 260 ms
38,656 KB
testcase_13 AC 511 ms
47,232 KB
testcase_14 AC 624 ms
42,600 KB
testcase_15 AC 322 ms
32,896 KB
testcase_16 AC 483 ms
42,940 KB
testcase_17 AC 296 ms
12,416 KB
testcase_18 AC 185 ms
23,936 KB
testcase_19 AC 103 ms
29,184 KB
testcase_20 AC 643 ms
43,620 KB
testcase_21 AC 207 ms
11,520 KB
testcase_22 AC 146 ms
15,744 KB
testcase_23 AC 75 ms
11,008 KB
testcase_24 AC 256 ms
40,704 KB
testcase_25 AC 306 ms
30,848 KB
testcase_26 AC 467 ms
43,264 KB
testcase_27 AC 429 ms
27,904 KB
testcase_28 AC 167 ms
18,560 KB
testcase_29 AC 308 ms
29,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod=1000000007
N,M=map(int,input().split())
st=[{i}for i in range(N)]
root=[i for i in range(N)]
ans=[1 for i in range(N)]
for i in range(M):
    A,B=map(int,input().split())
    A=root[A-1]
    B=root[B-1]
    if A==B:
        continue
    if len(st[A])<len(st[B]):
        A,B=B,A
    if len(st[A])!=len(st[B]):
        for i in st[B]:
            ans[i]=0
            root[i]=A
            st[A].add(i)
        st[B]={}
    else:
        for i in st[A]:
            ans[i]*=500000004
            ans[i]%=mod
        for i in st[B]:
            ans[i]*=500000004
            ans[i]%=mod
            root[i]=A
            st[A].add(i)
        st[B]={}
for i in ans:
    print(i)
0