結果
| 問題 | No.3482 Quod Erat Demonstrandum |
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2026-03-27 21:54:34 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 424 ms / 2,000 ms |
| コード長 | 1,180 bytes |
| 記録 | |
| コンパイル時間 | 197 ms |
| コンパイル使用メモリ | 85,268 KB |
| 実行使用メモリ | 145,664 KB |
| 最終ジャッジ日時 | 2026-03-27 21:54:49 |
| 合計ジャッジ時間 | 14,129 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 45 |
ソースコード
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("Different")
print(ANS)
else:
print("Unknown")
titia