結果

問題 No.1420 国勢調査 (Easy)
ユーザー ayaoniayaoni
提出日時 2021-03-05 22:45:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 375 ms / 2,000 ms
コード長 1,044 bytes
コンパイル時間 315 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 98,304 KB
最終ジャッジ日時 2024-04-16 10:32:29
合計ジャッジ時間 9,994 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
53,504 KB
testcase_01 AC 47 ms
53,632 KB
testcase_02 AC 234 ms
87,040 KB
testcase_03 AC 240 ms
86,528 KB
testcase_04 AC 236 ms
86,528 KB
testcase_05 AC 239 ms
86,528 KB
testcase_06 AC 237 ms
86,400 KB
testcase_07 AC 216 ms
86,016 KB
testcase_08 AC 204 ms
84,608 KB
testcase_09 AC 216 ms
86,400 KB
testcase_10 AC 215 ms
86,400 KB
testcase_11 AC 215 ms
86,016 KB
testcase_12 AC 113 ms
83,072 KB
testcase_13 AC 166 ms
87,040 KB
testcase_14 AC 111 ms
82,560 KB
testcase_15 AC 163 ms
87,424 KB
testcase_16 AC 173 ms
87,168 KB
testcase_17 AC 169 ms
87,040 KB
testcase_18 AC 171 ms
87,040 KB
testcase_19 AC 171 ms
87,296 KB
testcase_20 AC 170 ms
87,040 KB
testcase_21 AC 163 ms
87,040 KB
testcase_22 AC 375 ms
98,176 KB
testcase_23 AC 351 ms
97,792 KB
testcase_24 AC 364 ms
97,792 KB
testcase_25 AC 367 ms
98,304 KB
testcase_26 AC 366 ms
98,176 KB
testcase_27 AC 253 ms
92,416 KB
testcase_28 AC 250 ms
92,160 KB
testcase_29 AC 247 ms
92,160 KB
testcase_30 AC 250 ms
92,288 KB
testcase_31 AC 249 ms
92,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


N,M = MI()
Graph = [[] for _ in range(N+1)]
for _ in range(M):
    A,B = MI()
    Y = I()
    Graph[A].append((B,Y))
    Graph[B].append((A,Y))

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

    ANS[i] = 0
    deq = deque([i])
    while deq:
        j = deq.pop()
        for k,y in Graph[j]:
            if ANS[k] == -1:
                ANS[k] = ANS[j]^y
                deq.appendleft(k)
            else:
                if ANS[k] != ANS[j]^y:
                    print(-1)
                    exit()

print(*ANS[1:],sep='\n')
0