結果
問題 |
No.807 umg tours
|
ユーザー |
![]() |
提出日時 | 2019-10-26 17:53:10 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 2,672 ms / 4,000 ms |
コード長 | 1,294 bytes |
コンパイル時間 | 323 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 104,704 KB |
最終ジャッジ日時 | 2024-12-21 11:59:54 |
合計ジャッジ時間 | 27,182 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#!/usr/bin/env python3 import sys input = lambda: sys.stdin.readline()[:-1] sys.setrecursionlimit(10**8) inf=float('inf') import heapq def disktra(g,s): n=len(g) dist = [[inf]*2 for i in range(n)] maxd=[0]*n dist[s][0] = 0 dist[s][1]=0 hq=[] heapq.heappush(hq,(dist[s][0],s,0)) while hq: cost,u,used =heapq.heappop(hq) if dist[u][used] < cost: continue if used ==0: for v, c in g[u]: # print(dist[v][1]) # print(v) if dist[v][1] <= dist[u][0] :pass else: dist[v][1] = dist[u][0] heapq.heappush(hq, (dist[v][1], v, 1)) for v,c in g[u]: if dist[v][used] <= dist[u][used] +c: continue dist[v][used] = dist[u][used] + c heapq.heappush(hq,(dist[v][used],v,used)) return dist n,m=map(int,input().split()) abc=[] G=[[]*n for i in range(n)] G2=[[]*n for i in range(n)] for i in range(m): a,b,c=map(int,input().split()) a-=1;b-=1 G[a].append((b,c)) G[b].append((a,c)) d1=disktra(G,0) # d2=disktra(G,0) for i in range(n): ans=min(d1[i][1]+d1[i][0],d1[i][0]+d1[i][1]) print(ans) # print(d1) # print(d2)