結果
| 問題 | No.3482 Quod Erat Demonstrandum |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-03-27 21:45:07 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 903 ms / 2,000 ms |
| コード長 | 1,628 bytes |
| 記録 | |
| コンパイル時間 | 219 ms |
| コンパイル使用メモリ | 84,968 KB |
| 実行使用メモリ | 172,160 KB |
| 最終ジャッジ日時 | 2026-03-27 21:45:31 |
| 合計ジャッジ時間 | 22,059 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 45 |
ソースコード
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
g[a].append((b, int(1e9)))
g[b].append((a, int(1e9)))
dij = dijkstra(g).shortest_path(0)
if dij[-1] != float("inf") and dij[-1]//int(1e9) == 0:
print("Same")
print(dij[-1])
elif dij[-1] and dij[-1]//int(1e9) == 1:
print("Different")
print(dij[-1]//int(1e9)+dij[-1] % int(1e9))
else:
print("Unknown")