結果

問題 No.1420 国勢調査 (Easy)
ユーザー 👑 KazunKazun
提出日時 2021-03-05 22:11:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 328 ms / 2,000 ms
コード長 619 bytes
コンパイル時間 206 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 97,028 KB
最終ジャッジ日時 2024-04-16 09:45:30
合計ジャッジ時間 8,513 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
54,928 KB
testcase_01 AC 47 ms
54,568 KB
testcase_02 AC 173 ms
85,448 KB
testcase_03 AC 207 ms
86,784 KB
testcase_04 AC 177 ms
86,980 KB
testcase_05 AC 210 ms
86,656 KB
testcase_06 AC 192 ms
86,916 KB
testcase_07 AC 187 ms
84,480 KB
testcase_08 AC 162 ms
84,980 KB
testcase_09 AC 185 ms
84,096 KB
testcase_10 AC 164 ms
84,212 KB
testcase_11 AC 187 ms
84,444 KB
testcase_12 AC 96 ms
83,280 KB
testcase_13 AC 137 ms
84,736 KB
testcase_14 AC 93 ms
82,864 KB
testcase_15 AC 135 ms
85,120 KB
testcase_16 AC 135 ms
85,052 KB
testcase_17 AC 138 ms
85,248 KB
testcase_18 AC 132 ms
85,024 KB
testcase_19 AC 141 ms
85,248 KB
testcase_20 AC 132 ms
85,164 KB
testcase_21 AC 127 ms
84,880 KB
testcase_22 AC 328 ms
96,844 KB
testcase_23 AC 298 ms
97,020 KB
testcase_24 AC 315 ms
96,820 KB
testcase_25 AC 319 ms
96,920 KB
testcase_26 AC 305 ms
97,028 KB
testcase_27 AC 210 ms
90,472 KB
testcase_28 AC 221 ms
90,624 KB
testcase_29 AC 208 ms
90,620 KB
testcase_30 AC 220 ms
90,808 KB
testcase_31 AC 208 ms
91,100 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(M):
    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