結果
問題 | No.1301 Strange Graph Shortest Path |
ユーザー |
![]() |
提出日時 | 2020-11-28 00:11:43 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,986 bytes |
コンパイル時間 | 146 ms |
コンパイル使用メモリ | 82,448 KB |
実行使用メモリ | 143,904 KB |
最終ジャッジ日時 | 2024-07-26 21:20:18 |
合計ジャッジ時間 | 21,633 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 28 WA * 5 |
ソースコード
import sysinput = sys.stdin.readlineenum = enumerateinf = 1001001001002002002MOD = 998244353 #10**9 + 7import collectionsimport randomfrom bisect import bisect_right as bs_rfrom itertools import permutationsimport heapqdef linput(ty=int, cvt=list):return cvt(map(ty,input().split()))def vinput(rep=1, ty=int, cvt=list):return cvt(ty(input().rstrip()) for _ in range(rep))def gcd(a: int, b: int):while b: a, b = b, a%breturn adef lcm(a: int, b: int):return a * b // gcd(a, b)def dist(x1,y1,x2,y2):return abs(x1-x2)+abs(y1-y2)vD = [chr(ord("a")+i) for i in range(26)]def bye(res):sT = "No Yes".split()print(sT[res])#exit(0)def csum(v):vr = [0,]s = 0for a in v:s = (s+a)vr.append(s)return vrdef dijkstra(start, n, c_list):_vC = [inf,]*(n+1)_vC[start] = 0_vR = [0,]*(n+1) #set({})_vQ = [(0,start),]heapq.heapify(_vQ)while _vQ:_ci,_i = heapq.heappop(_vQ)if _vC[_i] < _ci:continuefor _cj,_j,_m in c_list[_i]:if _vC[_j] > _vC[_i] + _cj:_vC[_j] = _vC[_i] + _cj#_vM |= {_m,}_vR[_j] = _iheapq.heappush(_vQ, (_vC[_j],_j))return _vC, _vRdef main():N,M = linput()mT = [linput(int,tuple) for _ in range(M)]res = 0# 1st graphmG = [[] for _ in range(N+1)]for m, (u,v,c,d) in enum(mT):mG[u].append( (c,v,m) )mG[v].append( (c,u,m) )# dijkstra 1vC, vR = dijkstra(1, N, mG)#print(vC, vR)###res += vC[N]# find a pathvM = set({})vQ = [N,]while vQ:v = vQ.pop()u = vR[v]for c,gv,m in mG[u]:if gv==v:vQ.append(u)vM |= {m,}break# 2nd graphmG = [[] for _ in range(N+1)]for m, (u,v,c,d) in enum(mT):cost = d if m in vM else cmG[u].append( (cost,v,m) )mG[v].append( (cost,u,m) )# dijkstra 2vC, vR = dijkstra(N, N, mG)#print(vC)###res += vC[1]print(res)if __name__ == "__main__":main()