結果

問題 No.1420 国勢調査 (Easy)
ユーザー 👑 potato167potato167
提出日時 2022-02-17 02:06:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 416 ms / 2,000 ms
コード長 511 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 87,284 KB
実行使用メモリ 101,644 KB
最終ジャッジ日時 2023-09-11 17:22:16
合計ジャッジ時間 13,853 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,344 KB
testcase_01 AC 72 ms
71,020 KB
testcase_02 AC 294 ms
88,892 KB
testcase_03 AC 297 ms
88,836 KB
testcase_04 AC 298 ms
88,876 KB
testcase_05 AC 302 ms
89,328 KB
testcase_06 AC 292 ms
89,184 KB
testcase_07 AC 276 ms
86,948 KB
testcase_08 AC 277 ms
87,208 KB
testcase_09 AC 277 ms
86,788 KB
testcase_10 AC 271 ms
86,744 KB
testcase_11 AC 268 ms
86,936 KB
testcase_12 AC 168 ms
86,196 KB
testcase_13 AC 199 ms
87,040 KB
testcase_14 AC 164 ms
86,224 KB
testcase_15 AC 191 ms
86,952 KB
testcase_16 AC 196 ms
87,112 KB
testcase_17 AC 191 ms
86,932 KB
testcase_18 AC 198 ms
87,112 KB
testcase_19 AC 195 ms
87,220 KB
testcase_20 AC 192 ms
86,752 KB
testcase_21 AC 194 ms
87,040 KB
testcase_22 AC 407 ms
101,504 KB
testcase_23 AC 392 ms
101,192 KB
testcase_24 AC 394 ms
101,100 KB
testcase_25 AC 416 ms
100,692 KB
testcase_26 AC 405 ms
101,644 KB
testcase_27 AC 317 ms
94,240 KB
testcase_28 AC 319 ms
94,344 KB
testcase_29 AC 313 ms
94,384 KB
testcase_30 AC 323 ms
95,828 KB
testcase_31 AC 315 ms
94,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M=map(int,input().split())
G=[[(0,0) for j in range(0)] for i in range(N)]
for i in range(M):
	A,B=map(int,input().split())
	A-=1
	B-=1
	Y=int(input())
	G[A].append((B,Y))
	G[B].append((A,Y))
ans=[-1]*N
for i in range(N):
	if ans[i]!=-1:
		continue
	ans[i]=0
	order=[i]*1
	ind=0
	while ind!=len(order):
		a=order[ind]
		for x in G[a]:
			if ans[x[0]]==-1:
				ans[x[0]]=(ans[a]^x[1])
				order.append(x[0])
			elif ans[x[0]]!=(ans[a]^x[1]):
				print(-1)
				exit()
		ind+=1
for i in range(N):
	print(ans[i])
0