結果

問題 No.1420 国勢調査 (Easy)
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-03-05 22:18:00
言語 PyPy3
(7.3.13)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,052 bytes
コンパイル時間 2,289 ms
コンパイル使用メモリ 86,988 KB
実行使用メモリ 118,888 KB
最終ジャッジ日時 2023-07-29 02:15:42
合計ジャッジ時間 27,112 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
71,768 KB
testcase_01 AC 92 ms
71,728 KB
testcase_02 AC 501 ms
88,280 KB
testcase_03 AC 527 ms
88,396 KB
testcase_04 AC 628 ms
88,608 KB
testcase_05 AC 563 ms
88,608 KB
testcase_06 AC 685 ms
88,800 KB
testcase_07 AC 309 ms
88,204 KB
testcase_08 AC 265 ms
87,508 KB
testcase_09 AC 222 ms
86,348 KB
testcase_10 AC 224 ms
86,592 KB
testcase_11 AC 229 ms
86,588 KB
testcase_12 AC 196 ms
86,724 KB
testcase_13 AC 986 ms
109,264 KB
testcase_14 AC 141 ms
85,560 KB
testcase_15 AC 973 ms
109,552 KB
testcase_16 AC 966 ms
109,580 KB
testcase_17 AC 950 ms
109,960 KB
testcase_18 AC 933 ms
109,604 KB
testcase_19 AC 957 ms
109,544 KB
testcase_20 AC 993 ms
109,244 KB
testcase_21 AC 992 ms
109,560 KB
testcase_22 TLE -
testcase_23 TLE -
testcase_24 AC 1,877 ms
117,044 KB
testcase_25 AC 1,931 ms
117,884 KB
testcase_26 AC 1,971 ms
118,888 KB
testcase_27 AC 255 ms
93,928 KB
testcase_28 AC 247 ms
93,516 KB
testcase_29 AC 251 ms
93,668 KB
testcase_30 AC 253 ms
93,532 KB
testcase_31 AC 259 ms
93,704 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