結果
問題 | No.1451 集団登校 |
ユーザー | googol_S0 |
提出日時 | 2021-03-31 14:33:15 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 247 ms / 2,000 ms |
コード長 | 925 bytes |
コンパイル時間 | 261 ms |
コンパイル使用メモリ | 87,036 KB |
実行使用メモリ | 96,220 KB |
最終ジャッジ日時 | 2023-08-21 09:06:50 |
合計ジャッジ時間 | 6,069 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 73 ms
71,308 KB |
testcase_01 | AC | 71 ms
71,276 KB |
testcase_02 | AC | 73 ms
71,360 KB |
testcase_03 | AC | 72 ms
71,528 KB |
testcase_04 | AC | 73 ms
71,304 KB |
testcase_05 | AC | 72 ms
71,272 KB |
testcase_06 | AC | 72 ms
71,504 KB |
testcase_07 | AC | 71 ms
71,308 KB |
testcase_08 | AC | 189 ms
96,220 KB |
testcase_09 | AC | 73 ms
71,356 KB |
testcase_10 | AC | 159 ms
90,584 KB |
testcase_11 | AC | 111 ms
93,584 KB |
testcase_12 | AC | 170 ms
89,496 KB |
testcase_13 | AC | 212 ms
92,196 KB |
testcase_14 | AC | 224 ms
89,968 KB |
testcase_15 | AC | 179 ms
85,952 KB |
testcase_16 | AC | 208 ms
89,668 KB |
testcase_17 | AC | 134 ms
77,900 KB |
testcase_18 | AC | 155 ms
81,928 KB |
testcase_19 | AC | 85 ms
78,356 KB |
testcase_20 | AC | 247 ms
90,496 KB |
testcase_21 | AC | 107 ms
77,604 KB |
testcase_22 | AC | 142 ms
79,348 KB |
testcase_23 | AC | 84 ms
76,364 KB |
testcase_24 | AC | 158 ms
90,880 KB |
testcase_25 | AC | 183 ms
85,520 KB |
testcase_26 | AC | 209 ms
90,012 KB |
testcase_27 | AC | 193 ms
85,588 KB |
testcase_28 | AC | 150 ms
80,324 KB |
testcase_29 | AC | 183 ms
84,952 KB |
ソースコード
import sys input=sys.stdin.buffer.readline belong=list() group=list() ANS=[] mod=10**9+7 half=(mod+1)>>1 def init(X): global belong global group global ANS belong=list(range(X)) group=[[i] for i in range(X)] ANS=[1]*X def unite(x,y): if len(group[belong[x]])<len(group[belong[y]]): x,y=y,x if belong[x]==belong[y]: return True v=1 z=belong[y] if len(group[belong[x]])==len(group[z]): v=half else: for i in range(len(group[z])): ANS[group[z][i]]=0 for i in range(len(group[z])): belong[group[z][-1]]=belong[x] group[belong[x]].append(group[z][-1]) del group[z][-1] if v==half: for i in range(len(group[belong[x]])): ANS[group[belong[x]][i]]=ANS[group[belong[x]][i]]*v%mod return False N,M=map(int,input().split()) init(N) for i in range(M): a,b=map(int,input().split()) unite(a-1,b-1) for i in range(N): ANS[i]=str(ANS[i]) print('\n'.join(ANS))