結果

問題 No.1420 国勢調査 (Easy)
ユーザー chineristACchineristAC
提出日時 2021-03-05 21:35:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 351 ms / 2,000 ms
コード長 1,423 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 82,944 KB
実行使用メモリ 98,620 KB
最終ジャッジ日時 2024-04-16 09:00:08
合計ジャッジ時間 9,760 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
62,720 KB
testcase_01 AC 57 ms
62,336 KB
testcase_02 AC 222 ms
87,168 KB
testcase_03 AC 232 ms
86,912 KB
testcase_04 AC 222 ms
86,784 KB
testcase_05 AC 227 ms
86,784 KB
testcase_06 AC 228 ms
86,912 KB
testcase_07 AC 206 ms
87,296 KB
testcase_08 AC 205 ms
86,656 KB
testcase_09 AC 206 ms
87,040 KB
testcase_10 AC 209 ms
87,424 KB
testcase_11 AC 205 ms
86,912 KB
testcase_12 AC 117 ms
83,968 KB
testcase_13 AC 159 ms
87,296 KB
testcase_14 AC 119 ms
83,584 KB
testcase_15 AC 157 ms
87,424 KB
testcase_16 AC 164 ms
87,596 KB
testcase_17 AC 161 ms
87,552 KB
testcase_18 AC 157 ms
87,424 KB
testcase_19 AC 154 ms
87,680 KB
testcase_20 AC 159 ms
87,424 KB
testcase_21 AC 159 ms
87,680 KB
testcase_22 AC 329 ms
98,304 KB
testcase_23 AC 335 ms
98,432 KB
testcase_24 AC 317 ms
98,560 KB
testcase_25 AC 324 ms
98,432 KB
testcase_26 AC 351 ms
98,620 KB
testcase_27 AC 234 ms
93,440 KB
testcase_28 AC 227 ms
93,568 KB
testcase_29 AC 232 ms
93,440 KB
testcase_30 AC 237 ms
93,696 KB
testcase_31 AC 236 ms
93,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def cmb(n, r, mod):#コンビネーションの高速計算 
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return (g1[n] * g2[r] % mod) * g2[n-r] % mod

mod = 998244353#出力の制限
N = 2*10**3
g1 = [1]*(N+1) # 元テーブル
g2 = [1]*(N+1) #逆元テーブル
inverse = [1]*(N+1) #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1[i]=( ( g1[i-1] * i ) % mod )
    inverse[i]=( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2[i]=( (g2[i-1] * inverse[i]) % mod )
inverse[0]=0

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import log,gcd

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

N,M = mi()
edge = [[] for i in range(N)]
for _ in range(M):
    a,b = mi()
    y = int(input())
    edge[a-1].append((b-1,y))
    edge[b-1].append((a-1,y))

X = [0 for i in range(N)]
val = [False]*N

for i in range(N):
    if not val[i]:
        val[i] = True
        stack = [i]
        while stack:
            v = stack.pop()
            for nv,x in edge[v]:
                if val[nv]:
                    if X[v]^X[nv]!=x:
                        exit(print(-1))
                else:
                    val[nv] = True
                    X[nv] = X[v]^x
                    stack.append(nv)

print(*X,sep="\n")
0