結果
問題 |
No.1420 国勢調査 (Easy)
|
ユーザー |
|
提出日時 | 2021-03-15 09:04:32 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 782 bytes |
コンパイル時間 | 471 ms |
コンパイル使用メモリ | 81,664 KB |
実行使用メモリ | 139,484 KB |
最終ジャッジ日時 | 2024-11-06 22:21:41 |
合計ジャッジ時間 | 21,856 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 15 WA * 13 TLE * 2 |
ソースコード
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')