結果

問題 No.1420 国勢調査 (Easy)
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-03-05 22:18:00
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,052 bytes
コンパイル時間 382 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 121,224 KB
最終ジャッジ日時 2024-04-16 09:54:13
合計ジャッジ時間 26,763 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
53,888 KB
testcase_01 AC 46 ms
53,504 KB
testcase_02 AC 542 ms
87,040 KB
testcase_03 AC 541 ms
86,912 KB
testcase_04 AC 648 ms
87,296 KB
testcase_05 AC 547 ms
87,168 KB
testcase_06 AC 655 ms
87,168 KB
testcase_07 AC 284 ms
86,656 KB
testcase_08 AC 223 ms
85,376 KB
testcase_09 AC 196 ms
84,352 KB
testcase_10 AC 191 ms
84,352 KB
testcase_11 AC 194 ms
84,224 KB
testcase_12 AC 161 ms
85,120 KB
testcase_13 AC 933 ms
108,032 KB
testcase_14 AC 106 ms
83,840 KB
testcase_15 AC 911 ms
108,288 KB
testcase_16 AC 937 ms
108,032 KB
testcase_17 AC 941 ms
108,288 KB
testcase_18 AC 929 ms
108,032 KB
testcase_19 AC 954 ms
108,160 KB
testcase_20 AC 936 ms
108,032 KB
testcase_21 AC 913 ms
107,904 KB
testcase_22 TLE -
testcase_23 TLE -
testcase_24 AC 1,927 ms
121,224 KB
testcase_25 TLE -
testcase_26 AC 1,913 ms
121,060 KB
testcase_27 AC 225 ms
91,648 KB
testcase_28 AC 222 ms
91,520 KB
testcase_29 AC 225 ms
91,648 KB
testcase_30 AC 227 ms
91,520 KB
testcase_31 AC 223 ms
91,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

桁ごとに求められる
1箇所決め打てば、後は連鎖的に決まる
桁ごとにdfsして、矛盾なければおk

"""

import sys
from sys import stdin
from collections import deque  

N,M = map(int,stdin.readline().split())

lis = [ [] for i in range(N) ]

for i in range(M):

    A,B = map(int,stdin.readline().split())
    A -= 1
    B -= 1

    Y = int(stdin.readline())

    lis[A].append((B,Y))
    lis[B].append((A,Y))

ans = [0] * N

for dig in range(30):

    nd = 2**dig
    able = [True] * N

    for st in range(N):

        if able[st]:

            q = deque([st])
            able[st] = False

            while q:
                v = q.popleft()

                for nex,Y in lis[v]:
                    if able[nex]:
                        able[nex] = False
                        ans[nex] |= (Y ^ ans[v]) & nd
                        q.append(nex)
                    elif ans[nex] & nd != (Y ^ ans[v]) & nd:
                        print (-1)
                        sys.exit()

print ("\n".join(map(str,ans)))
0