結果

問題 No.1420 国勢調査 (Easy)
ユーザー titiatitia
提出日時 2021-03-05 22:16:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 288 ms / 2,000 ms
コード長 699 bytes
コンパイル時間 153 ms
コンパイル使用メモリ 82,468 KB
実行使用メモリ 97,560 KB
最終ジャッジ日時 2024-04-16 09:51:12
合計ジャッジ時間 7,865 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
52,096 KB
testcase_01 AC 35 ms
51,968 KB
testcase_02 AC 176 ms
85,052 KB
testcase_03 AC 185 ms
86,632 KB
testcase_04 AC 190 ms
86,784 KB
testcase_05 AC 189 ms
86,528 KB
testcase_06 AC 187 ms
86,400 KB
testcase_07 AC 165 ms
84,096 KB
testcase_08 AC 161 ms
84,608 KB
testcase_09 AC 164 ms
83,712 KB
testcase_10 AC 161 ms
83,724 KB
testcase_11 AC 156 ms
84,072 KB
testcase_12 AC 85 ms
82,432 KB
testcase_13 AC 122 ms
86,936 KB
testcase_14 AC 84 ms
82,560 KB
testcase_15 AC 120 ms
86,272 KB
testcase_16 AC 120 ms
87,168 KB
testcase_17 AC 119 ms
86,896 KB
testcase_18 AC 115 ms
87,044 KB
testcase_19 AC 120 ms
86,656 KB
testcase_20 AC 119 ms
86,912 KB
testcase_21 AC 116 ms
86,396 KB
testcase_22 AC 278 ms
97,280 KB
testcase_23 AC 279 ms
97,320 KB
testcase_24 AC 275 ms
97,184 KB
testcase_25 AC 288 ms
97,280 KB
testcase_26 AC 287 ms
97,560 KB
testcase_27 AC 193 ms
90,112 KB
testcase_28 AC 191 ms
90,240 KB
testcase_29 AC 189 ms
90,304 KB
testcase_30 AC 194 ms
90,816 KB
testcase_31 AC 192 ms
90,088 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