結果
| 問題 | No.3482 Quod Erat Demonstrandum |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-03-27 21:28:17 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,565 bytes |
| 記録 | |
| コンパイル時間 | 1,540 ms |
| コンパイル使用メモリ | 84,964 KB |
| 実行使用メモリ | 173,112 KB |
| 最終ジャッジ日時 | 2026-03-27 21:28:55 |
| 合計ジャッジ時間 | 26,771 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 27 WA * 18 |
ソースコード
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)]
g2 = [[] for _ in range(n)]
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:
g2[a].append((b, 1))
g2[b].append((a, 1))
dij = dijkstra(g).shortest_path(0)
dij2 = dijkstra(g2).shortest_path(0)
if dij[-1] != float("inf"):
print("Same")
print(dij[-1])
elif dij2[-1] != float("inf"):
print("Different")
print(dij2[-1])
else:
print("Unknown")