結果

問題 No.3482 Quod Erat Demonstrandum
コンテスト
ユーザー moon17
提出日時 2026-03-27 22:05:03
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 735 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 549 ms
コンパイル使用メモリ 84,992 KB
実行使用メモリ 117,760 KB
最終ジャッジ日時 2026-03-27 22:05:24
合計ジャッジ時間 20,588 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 14 WA * 31
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

def find(x):
 q=[]
 while uf[x]^x:q+=x,;x=uf[x]
 for p in q:uf[p]=x
 return x
def unite(x,y):
 x,y=find(x),find(y)
 if x^y:uf[x]=y
for _ in range(int(input())):
  n,m=map(int,input().split())
  abc=[[*map(int,input().split())]for _ in range(m)]
  uf=[*range(n)]
  d=s=0
  for a,b,c in abc:
    a-=1;b-=1
    if c==1:
      unite(a,b)
  u,v=find(0),find(n-1)
  if find(0)==find(n-1):
    s=1
  for a,b,c in abc:
    a-=1;b-=1
    l=find(a),find(b)
    if c==2:
      if l in[(u,v),(v,u)]:
        d=1
  t=0
  for i in range(n):
    if u==find(i):
      t+=1
  if s>d:
    print('Same')
    print(t-1)
  elif s<d:
    for i in range(n):
      if find(i)==v:
        t+=1
    print('Different')
    print(t-1)
  else:
    print('Unknown')
0