結果

問題 No.3482 Quod Erat Demonstrandum
コンテスト
ユーザー titia
提出日時 2026-03-27 21:53:11
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 1,181 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 351 ms
コンパイル使用メモリ 85,404 KB
実行使用メモリ 145,664 KB
最終ジャッジ日時 2026-03-27 21:53:34
合計ジャッジ時間 12,173 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other AC * 30 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline

from collections import deque

T=int(input())

for tests in range(T):
    N,M=list(map(int,input().split()))
    S=[list(map(int,input().split())) for i in range(M)]

    E=[[] for i in range(N+1)]


    for a,b,c in S:

        if c==1:
            E[a].append(b)
            E[b].append(a)

    D1=[1<<30]*(N+1)
    D2=[1<<30]*(N+1)

    Q=deque([1])
    D1[1]=0

    while Q:
        x=Q.popleft()
        for to in E[x]:
             if D1[to]>D1[x]+1:
                 D1[to]=D1[x]+1
                 Q.append(to)
    

    if D1[N]<N*2:
        ANS=D1[N]
        print("Same")
        print(ANS)
        continue

    Q=deque([N])
    D2[N]=0

    while Q:
        x=Q.popleft()
        for to in E[x]:
             if D2[to]>D2[x]+1:
                 D2[to]=D2[x]+1
                 Q.append(to)

    ANS=1<<30

    for a,b,c in S:
        if c==2:
            if D1[a]<N*2 and D2[b]<N*2:
                ANS=min(ANS,D1[a]+D2[b]+1)
            if D1[b]<N*2 and D2[a]<N*2:
                ANS=min(ANS,D1[b]+D2[a]+1)

    if ANS<2*N:
        print("Differenct")
        print(ANS)
    else:
        print("Unknown")
        

    

    
0