結果

問題 No.1451 集団登校
ユーザー googol_S0googol_S0
提出日時 2021-03-31 14:30:07
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 907 bytes
コンパイル時間 289 ms
コンパイル使用メモリ 86,908 KB
実行使用メモリ 96,232 KB
最終ジャッジ日時 2023-08-21 09:04:18
合計ジャッジ時間 7,201 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,496 KB
testcase_01 AC 72 ms
71,224 KB
testcase_02 AC 72 ms
71,400 KB
testcase_03 AC 71 ms
71,500 KB
testcase_04 AC 73 ms
71,352 KB
testcase_05 AC 73 ms
71,300 KB
testcase_06 AC 73 ms
71,404 KB
testcase_07 AC 73 ms
71,268 KB
testcase_08 AC 180 ms
96,232 KB
testcase_09 AC 71 ms
71,516 KB
testcase_10 AC 158 ms
90,088 KB
testcase_11 AC 110 ms
93,584 KB
testcase_12 AC 166 ms
89,492 KB
testcase_13 AC 311 ms
92,764 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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]
  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))
0