結果

問題 No.1420 国勢調査 (Easy)
ユーザー titiatitia
提出日時 2021-03-05 22:16:07
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 340 ms / 2,000 ms
コード長 699 bytes
コンパイル時間 1,134 ms
コンパイル使用メモリ 87,080 KB
実行使用メモリ 98,300 KB
最終ジャッジ日時 2023-07-29 02:11:43
合計ジャッジ時間 10,750 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,200 KB
testcase_01 AC 73 ms
71,372 KB
testcase_02 AC 221 ms
85,980 KB
testcase_03 AC 222 ms
87,624 KB
testcase_04 AC 229 ms
87,396 KB
testcase_05 AC 223 ms
87,420 KB
testcase_06 AC 231 ms
87,400 KB
testcase_07 AC 209 ms
87,120 KB
testcase_08 AC 194 ms
85,716 KB
testcase_09 AC 207 ms
87,112 KB
testcase_10 AC 201 ms
84,920 KB
testcase_11 AC 200 ms
84,944 KB
testcase_12 AC 119 ms
83,552 KB
testcase_13 AC 156 ms
87,504 KB
testcase_14 AC 116 ms
83,436 KB
testcase_15 AC 152 ms
87,356 KB
testcase_16 AC 157 ms
87,480 KB
testcase_17 AC 156 ms
87,804 KB
testcase_18 AC 157 ms
87,672 KB
testcase_19 AC 154 ms
87,528 KB
testcase_20 AC 156 ms
87,568 KB
testcase_21 AC 160 ms
87,344 KB
testcase_22 AC 333 ms
98,244 KB
testcase_23 AC 334 ms
98,300 KB
testcase_24 AC 325 ms
98,084 KB
testcase_25 AC 337 ms
97,992 KB
testcase_26 AC 340 ms
98,076 KB
testcase_27 AC 232 ms
91,528 KB
testcase_28 AC 234 ms
91,340 KB
testcase_29 AC 234 ms
91,368 KB
testcase_30 AC 236 ms
91,400 KB
testcase_31 AC 229 ms
91,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

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

ANS=[-1]*(N+1)

for i in range(1,N+1):
    if ANS[i]==-1:
        Q=[i]
        ANS[i]=0
        
        while Q:
            x=Q.pop()

            for to,xor in E[x]:
                if ANS[to]==-1:
                    ANS[to]=ANS[x]^xor
                    Q.append(to)
                else:
                    if ANS[to]^ANS[x]!=xor:
                        print(-1)
                        sys.exit()

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

print(*ANS[1:])
0