結果

問題 No.1420 国勢調査 (Easy)
ユーザー 👑 KazunKazun
提出日時 2021-03-05 22:10:03
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 619 bytes
コンパイル時間 228 ms
コンパイル使用メモリ 82,588 KB
実行使用メモリ 97,224 KB
最終ジャッジ日時 2024-04-16 09:39:15
合計ジャッジ時間 8,974 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
55,656 KB
testcase_01 AC 39 ms
54,460 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 294 ms
96,980 KB
testcase_23 AC 274 ms
96,760 KB
testcase_24 AC 288 ms
96,944 KB
testcase_25 AC 303 ms
96,996 KB
testcase_26 AC 302 ms
97,224 KB
testcase_27 AC 195 ms
90,536 KB
testcase_28 AC 197 ms
90,700 KB
testcase_29 AC 188 ms
90,988 KB
testcase_30 AC 200 ms
90,848 KB
testcase_31 AC 200 ms
90,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque
input=sys.stdin.readline
write=sys.stdout.write

N,M=map(int,input().split())
E=[[] for _ in range(N+1)]
for _ in range(N):
    a,b=map(int,input().split())
    y=int(input())

    E[a].append((b,y))
    E[b].append((a,y))

X=[-1]*(N+1)
for v in range(1,N+1):
    if X[v]!=-1:
        continue

    X[v]=0
    Q=deque([v])
    while Q:
        w=Q.popleft()

        for u,y in E[w]:
            if X[u]==-1:
                X[u]=X[w]^y
                Q.append(u)
            elif X[w]^X[u]!=y:
                print(-1)
                exit()

write("\n".join(map(str,X[1:])))
0