結果

問題 No.1420 国勢調査 (Easy)
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-03-15 09:25:25
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,237 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 296,812 KB
最終ジャッジ日時 2024-04-24 14:18:50
合計ジャッジ時間 20,316 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
57,600 KB
testcase_01 AC 43 ms
52,224 KB
testcase_02 AC 543 ms
115,208 KB
testcase_03 AC 523 ms
114,708 KB
testcase_04 AC 520 ms
114,312 KB
testcase_05 AC 465 ms
114,828 KB
testcase_06 AC 583 ms
114,576 KB
testcase_07 AC 319 ms
111,508 KB
testcase_08 AC 238 ms
100,756 KB
testcase_09 AC 229 ms
106,896 KB
testcase_10 AC 219 ms
107,028 KB
testcase_11 AC 219 ms
107,068 KB
testcase_12 AC 187 ms
104,072 KB
testcase_13 AC 1,098 ms
207,872 KB
testcase_14 AC 138 ms
100,864 KB
testcase_15 AC 1,017 ms
208,328 KB
testcase_16 AC 877 ms
209,092 KB
testcase_17 AC 895 ms
207,932 KB
testcase_18 AC 930 ms
206,396 KB
testcase_19 AC 882 ms
207,800 KB
testcase_20 AC 1,071 ms
208,644 KB
testcase_21 AC 905 ms
209,272 KB
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=sys.stdin.readline
def main1(n,m,aby):
  g=[[] for _ in range(n)]
  for a,b,y in aby:
    a,b=a-1,b-1
    g[a].append([b,y])
    g[b].append([a,y])
  x=[0]*n
  flg=True
  for i in range(30):
    bit=1<<i
    mi=set(range(n))
    seen=[-1]*n
    while mi:
      v0=mi.pop()
      grp={v0}
      for d in (0,bit):
        flg=True
        seen[v0]=d
        todo=[v0]
        while todo:
          v=todo.pop()
          mi.discard(v)
          grp.add(v)
          for nv,y in g[v]:
            if seen[nv]==-1:
              seen[nv]=seen[v]^(y&bit)
              todo.append(nv)
            elif seen[nv]==seen[v]^(y&bit):
              continue
            else:
              flg=False
              break
          if not flg:break
        if flg:
          for v in grp:
            if seen[v]>0:
              x[v]+=bit
          break
      if not flg:return [-1]
  return x

def chk(n,aby,x):
  for a,b,y in aby:
    a,b=a-1,b-1
    if x[a]^x[b]==y:
      pass
    else:
      return False
  return True

if __name__=='__main__':
  n,m=map(int,input().split())
  aby=[]
  for _ in range(m):
    a,b=map(int,input().split())
    y=int(input())
    aby.append([a,b,y])
  ret1=main1(n,m,aby)
  print(*ret1,sep='\n')
0