結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
回転
|
| 提出日時 | 2025-10-15 23:48:21 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,208 bytes |
| コンパイル時間 | 344 ms |
| コンパイル使用メモリ | 82,360 KB |
| 実行使用メモリ | 328,120 KB |
| 最終ジャッジ日時 | 2025-10-15 23:48:29 |
| 合計ジャッジ時間 | 8,231 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 11 TLE * 1 -- * 14 |
ソースコード
import heapq
import sys
input = sys.stdin.readline
def main():
N,M = list(map(int,input().split()))
edge = [[] for _ in range(N)]
for _ in range(M):
a,b,c = list(map(int,input().split()))
a -= 1;b -= 1
edge[a].append((b,c))
edge[b].append((a,c))
geta = 10**14+1
def make_hash(a,b,c):
return b * geta * geta + c * geta + a
def read_hash(n):
a = n % geta
n //= geta
c = n % geta
n //= geta
b = n % geta
return a,b,c
INF = 10**18
visited = [INF for _ in range(2*N)]
q = [make_hash(0,0,0), make_hash(0,1,0)]
while(q):
v,use,now = read_hash(heapq.heappop(q))
if(visited[2*now+use] <= v):continue
visited[2*now+use] = v
if(not use):
# チケット使用
for a,c in edge[now]:
if(visited[2*a+1] <= v):continue
heapq.heappush(q,make_hash(v,1,a))
# チケット保持
for a,c in edge[now]:
if(visited[2*a+use] <= v+c):continue
heapq.heappush(q,make_hash(v+c,use,a))
for i in range(N):
print(visited[2*i] + visited[2*i+1])
main()
回転