結果

問題 No.1451 集団登校
ユーザー shiomusubi496shiomusubi496
提出日時 2021-03-25 10:58:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 752 ms / 2,000 ms
コード長 679 bytes
コンパイル時間 149 ms
コンパイル使用メモリ 10,968 KB
実行使用メモリ 44,872 KB
最終ジャッジ日時 2023-08-18 00:51:11
合計ジャッジ時間 8,849 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,884 KB
testcase_01 AC 16 ms
7,880 KB
testcase_02 AC 17 ms
7,792 KB
testcase_03 AC 16 ms
7,760 KB
testcase_04 AC 16 ms
7,864 KB
testcase_05 AC 16 ms
7,912 KB
testcase_06 AC 16 ms
7,884 KB
testcase_07 AC 16 ms
7,808 KB
testcase_08 AC 752 ms
44,872 KB
testcase_09 AC 16 ms
7,848 KB
testcase_10 AC 284 ms
38,912 KB
testcase_11 AC 165 ms
38,824 KB
testcase_12 AC 260 ms
35,864 KB
testcase_13 AC 530 ms
44,312 KB
testcase_14 AC 634 ms
40,108 KB
testcase_15 AC 309 ms
30,084 KB
testcase_16 AC 469 ms
40,404 KB
testcase_17 AC 273 ms
9,796 KB
testcase_18 AC 184 ms
21,112 KB
testcase_19 AC 92 ms
26,440 KB
testcase_20 AC 670 ms
41,092 KB
testcase_21 AC 180 ms
8,848 KB
testcase_22 AC 129 ms
13,132 KB
testcase_23 AC 58 ms
8,284 KB
testcase_24 AC 265 ms
38,068 KB
testcase_25 AC 307 ms
28,116 KB
testcase_26 AC 456 ms
40,416 KB
testcase_27 AC 439 ms
25,236 KB
testcase_28 AC 166 ms
15,868 KB
testcase_29 AC 326 ms
27,268 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