結果
| 問題 | No.3482 Quod Erat Demonstrandum |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-03-27 21:36:31 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,672 bytes |
| 記録 | |
| コンパイル時間 | 233 ms |
| コンパイル使用メモリ | 85,804 KB |
| 実行使用メモリ | 203,384 KB |
| 最終ジャッジ日時 | 2026-03-27 21:37:58 |
| 合計ジャッジ時間 | 26,758 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 32 WA * 13 |
ソースコード
import heapq
from itertools import product
from itertools import permutations
import random
import math
import bisect
import sys
from collections import defaultdict
from itertools import combinations
inf = 1 << 60
def exit():
sys.exit()
def LI():
return list(map(int, input().split()))
def II():
return int(input())
def SI():
return input()
class dijkstra:
def __init__(self, g):
self.g = g
def shortest_path(self, start):
import heapq
n = len(self.g)
dist = [float("inf")] * n
dist[start] = 0
pq = [(0, start)]
while pq:
d, u = heapq.heappop(pq)
if dist[u] < d:
continue
for v, w in self.g[u]:
nd = d + w
if dist[v] > nd:
dist[v] = nd
heapq.heappush(pq, (nd, v))
return dist
t = II()
for _ in range(t):
n, m = LI()
items = [LI() for _ in range(m)]
g = [[] for _ in range(n)]
dic = defaultdict(bool)
for item in items:
a, b, c = item
a, b = a-1, b-1
if c == 1:
g[a].append((b, 1))
g[b].append((a, 1))
elif c == 2:
dic[(a, b)] = True
dij = dijkstra(g).shortest_path(0)
dij2 = dijkstra(g).shortest_path(n-1)
mn = inf
for i in range(n-1):
if dij[i] != float("inf") and dij2[i+1] != float("inf") and dic[(i, i+1)]:
mn = min(mn, dij[i]+dij2[i+1]+1)
if dij[-1] != float("inf"):
print("Same")
print(dij[-1])
elif mn != inf:
print("Different")
print(mn)
else:
print("Unknown")