結果
| 問題 | No.3482 Quod Erat Demonstrandum |
| コンテスト | |
| ユーザー |
ゼット
|
| 提出日時 | 2026-03-27 22:39:48 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 389 ms / 2,000 ms |
| コード長 | 747 bytes |
| 記録 | |
| コンパイル時間 | 506 ms |
| コンパイル使用メモリ | 85,632 KB |
| 実行使用メモリ | 126,736 KB |
| 最終ジャッジ日時 | 2026-03-27 22:40:35 |
| 合計ジャッジ時間 | 18,287 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 45 |
ソースコード
Q=int(input())
for _ in range(Q):
N,M=map(int,input().split())
G=[[] for i in range(N)]
for i in range(M):
a,b,c=map(int,input().split())
G[a-1].append((b-1,c))
G[b-1].append((a-1,c))
dist=[10**10]*(2*N)
dist[0]=0
from collections import deque
S=deque()
S.append(0)
while S:
x=S.popleft()
a,b=x//2,x&1
for B in G[a]:
y,c=B[:]
b2=b^(c-1)
if b==1 and b2==0:
continue
if dist[2*y+b2]==10**10:
dist[2*y+b2]=dist[x]+1
S.append(2*y+b2)
if dist[2*(N-1)]==10**10 and dist[2*(N-1)+1]==10**10:
print('Unknown')
else:
if dist[2*(N-1)]<=dist[2*(N-1)+1]:
print('Same')
else:
print('Different')
print(min(dist[2*(N-1)],dist[2*(N-1)+1]))
ゼット