結果

問題 No.1420 国勢調査 (Easy)
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-03-15 08:53:17
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 785 bytes
コンパイル時間 313 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 140,116 KB
最終ジャッジ日時 2024-04-24 13:52:40
合計ジャッジ時間 17,686 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,224 KB
testcase_01 AC 36 ms
52,224 KB
testcase_02 AC 504 ms
107,668 KB
testcase_03 AC 481 ms
107,156 KB
testcase_04 AC 410 ms
107,172 KB
testcase_05 AC 462 ms
107,024 KB
testcase_06 AC 474 ms
106,904 KB
testcase_07 AC 265 ms
106,792 KB
testcase_08 AC 209 ms
99,492 KB
testcase_09 AC 200 ms
106,520 KB
testcase_10 AC 208 ms
106,664 KB
testcase_11 AC 211 ms
106,404 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 260 ms
114,552 KB
testcase_28 AC 259 ms
114,624 KB
testcase_29 AC 276 ms
114,524 KB
testcase_30 AC 266 ms
114,908 KB
testcase_31 AC 261 ms
114,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=sys.stdin.readline
n,m=map(int,input().split())
aby=[]
for _ in range(m):
  a,b=map(int,input().split())
  y=int(input())
  aby.append([a,b,y])
g=[[] for _ in range(n)]
for a,b,y in aby:
  a,b=a-1,b-1
  g[a].append([b,y])
  g[b].append([a,y])
x=[0]*n
flg=True
for i in range(30):
  seen=[-1]*n
  for d in (0,1):
    flg=True
    seen[0]=d
    todo=[0]
    while todo:
      v=todo.pop()
      for nv,y in g[v]:
        if seen[nv]==-1:
          seen[nv]=seen[v]^(y>>i)&1
          todo.append(nv)
        elif seen[nv]==seen[v]^(y>>i)&1:
          continue
        else:
          flg=False
          break
    if flg:
      for v in range(n):
       if seen[v]==1:
         x[v]+=1<<i
      break
  if not flg:break
if not flg:
  print(-1)
else:
  print(*x,sep='\n')
0