結果

問題 No.1420 国勢調査 (Easy)
ユーザー roarisroaris
提出日時 2021-03-05 22:07:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 424 ms / 2,000 ms
コード長 858 bytes
コンパイル時間 252 ms
コンパイル使用メモリ 82,484 KB
実行使用メモリ 127,344 KB
最終ジャッジ日時 2024-04-16 09:36:43
合計ジャッジ時間 11,071 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
53,964 KB
testcase_01 AC 43 ms
54,184 KB
testcase_02 AC 315 ms
119,536 KB
testcase_03 AC 307 ms
120,068 KB
testcase_04 AC 312 ms
119,996 KB
testcase_05 AC 315 ms
120,004 KB
testcase_06 AC 311 ms
119,920 KB
testcase_07 AC 286 ms
114,448 KB
testcase_08 AC 277 ms
114,420 KB
testcase_09 AC 286 ms
114,412 KB
testcase_10 AC 280 ms
114,140 KB
testcase_11 AC 283 ms
114,456 KB
testcase_12 AC 91 ms
83,392 KB
testcase_13 AC 157 ms
87,168 KB
testcase_14 AC 91 ms
83,104 KB
testcase_15 AC 162 ms
87,548 KB
testcase_16 AC 166 ms
87,096 KB
testcase_17 AC 160 ms
87,268 KB
testcase_18 AC 164 ms
87,068 KB
testcase_19 AC 163 ms
86,704 KB
testcase_20 AC 165 ms
87,084 KB
testcase_21 AC 159 ms
86,688 KB
testcase_22 AC 424 ms
126,936 KB
testcase_23 AC 412 ms
127,116 KB
testcase_24 AC 411 ms
126,724 KB
testcase_25 AC 422 ms
126,940 KB
testcase_26 AC 419 ms
127,344 KB
testcase_27 AC 306 ms
119,296 KB
testcase_28 AC 302 ms
119,912 KB
testcase_29 AC 295 ms
119,580 KB
testcase_30 AC 302 ms
119,576 KB
testcase_31 AC 297 ms
119,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import *

N, M = map(int, input().split())
G = [[] for _ in range(N)]
d = defaultdict(set)

for _ in range(M):
    A, B = map(int, input().split())
    Y = int(input())
    G[A-1].append((B-1, Y))
    G[B-1].append((A-1, Y))
    d[10**6*min(A, B)+max(A, B)].add(Y)

for k in d:
    if len(d[k])>=2:
        print(-1)
        exit()
        
ans = [-1]*N

for v in range(N):
    if ans[v]==-1:
        ans[v] = 0
        q = deque([v])
        
        while q:
            v = q.popleft()
            
            for nv, Y in G[v]:
                if ans[nv]==-1:
                    ans[nv] = ans[v]^Y
                    q.append(nv)
                else:
                    if ans[v]^ans[nv]!=Y:
                        print(-1)
                        exit()

for i in range(N):
    print(ans[i])
0