結果

問題 No.1420 国勢調査 (Easy)
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-03-15 09:04:32
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 782 bytes
コンパイル時間 601 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 140,248 KB
最終ジャッジ日時 2024-04-24 14:00:40
合計ジャッジ時間 18,663 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,224 KB
testcase_01 AC 36 ms
52,096 KB
testcase_02 AC 572 ms
107,416 KB
testcase_03 AC 485 ms
107,036 KB
testcase_04 AC 422 ms
107,040 KB
testcase_05 AC 466 ms
107,296 KB
testcase_06 AC 559 ms
107,048 KB
testcase_07 AC 296 ms
107,168 KB
testcase_08 AC 237 ms
100,128 KB
testcase_09 AC 228 ms
106,380 KB
testcase_10 AC 228 ms
106,656 KB
testcase_11 AC 228 ms
106,908 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 337 ms
115,412 KB
testcase_28 AC 350 ms
115,796 KB
testcase_29 AC 341 ms
115,312 KB
testcase_30 AC 338 ms
115,548 KB
testcase_31 AC 338 ms
115,544 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):
  bit=1<<i
  for d in (0,bit):
    seen=[-1]*n
    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&bit)
          todo.append(nv)
        elif seen[nv]==seen[v]^(y&bit):
          continue
        else:
          flg=False
          break
    if flg:
      for v in range(n):
       if seen[v]:
         x[v]+=bit
      break
  if not flg:
    print(-1)
    exit()
print(*x,sep='\n')
0