結果

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

ソースコード

diff #
raw source code

from collections import*
def f(s):
  q=deque([s])
  vs=[-1]*n
  vs[s]=0
  while q:
    p=q.popleft()
    for v in g[p]:
      if vs[v]==-1:
        vs[v]=vs[p]+1
        q+=v,
  return vs
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
  g=[[]for _ in range(n)]
  for a,b,c in abc:
    a-=1;b-=1
    if c==1:
      unite(a,b)
      g[a]+=b,
      g[b]+=a,
  u,v=find(0),find(n-1)
  if u==v:
    s=1
  s0=f(0)
  sn=f(n-1)
  mn=1<<60
  for a,b,c in abc:
    a-=1;b-=1
    la,lb=find(a),find(b)
    if c==2:
      if (la,lb)==(u,v):
        mn=min(mn,s0[a]+1+sn[b])
        d=1
      if (la,lb)==(v,u):
        mn=min(mn,s0[b]+1+sn[a])
  if s>d:
    print('Same')
    print(s0[n-1])
  elif s<d:
    print('Different')
    print(mn)
  else:
    print('Unknown')
0