結果

問題 No.1301 Strange Graph Shortest Path
ユーザー ygd.ygd.
提出日時 2020-11-27 22:44:22
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,259 bytes
コンパイル時間 461 ms
コンパイル使用メモリ 87,076 KB
実行使用メモリ 137,644 KB
最終ジャッジ日時 2023-10-09 21:41:32
合計ジャッジ時間 25,271 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
71,224 KB
testcase_01 AC 68 ms
71,280 KB
testcase_02 WA -
testcase_03 AC 598 ms
116,076 KB
testcase_04 AC 779 ms
135,532 KB
testcase_05 AC 531 ms
116,504 KB
testcase_06 AC 714 ms
130,248 KB
testcase_07 AC 687 ms
125,952 KB
testcase_08 AC 605 ms
115,732 KB
testcase_09 AC 736 ms
128,640 KB
testcase_10 WA -
testcase_11 AC 748 ms
129,900 KB
testcase_12 AC 763 ms
131,404 KB
testcase_13 AC 688 ms
123,752 KB
testcase_14 AC 716 ms
126,352 KB
testcase_15 AC 677 ms
124,404 KB
testcase_16 AC 800 ms
137,088 KB
testcase_17 AC 741 ms
127,388 KB
testcase_18 AC 685 ms
122,272 KB
testcase_19 AC 746 ms
130,556 KB
testcase_20 AC 726 ms
132,440 KB
testcase_21 AC 704 ms
127,776 KB
testcase_22 AC 710 ms
133,644 KB
testcase_23 AC 697 ms
125,404 KB
testcase_24 AC 739 ms
132,240 KB
testcase_25 AC 803 ms
134,004 KB
testcase_26 AC 745 ms
128,696 KB
testcase_27 AC 749 ms
129,480 KB
testcase_28 AC 620 ms
118,708 KB
testcase_29 WA -
testcase_30 AC 821 ms
132,828 KB
testcase_31 AC 777 ms
133,008 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 612 ms
126,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heapify, heappop, heappush
N,M = map(int,input().split()); INF = float("inf")
Graph = [[] for _ in range(N)]
INPUT = []
for i in range(M):
    s,g,x,y = map(int,input().split()); INPUT.append((s,g,x,y))
    s-=1;g-=1
    Graph[s].append((x,g))
    Graph[g].append((x,s))

def dijkstra_heap2(s,G):
  #S:start, V: node, E: Edge, G: Graph
  V = len(G)
  d = [INF for _ in range(V)]
  d[s] = 0
  prev = [0]*V
  prev[s] = -1
  PQ = []
  heappush(PQ,(0,s))
  
  while PQ:
    c,v = heappop(PQ)
    if d[v] < c:
      continue
    d[v] = c
    for cost,u in G[v]:
      if d[u] <= cost + d[v]:
        continue
      d[u] = cost + d[v]
      prev[u] = v
      heappush(PQ,(d[u], u))
  
  return d ,prev

D,PREV = dijkstra_heap2(0,Graph)
#print(D)
ans = D[N-1]
#print(PREV)
now = N-1
Used = set()
while now != 0:
    mae = now
    now = PREV[mae]
    Used.add((mae,now))
Graph.clear()
New_Graph = [[] for _ in range(N)]
for P in INPUT:
    a,b,x,y = P
    a-=1;b-=1
    if (a,b) in Used or (b,a) in Used:
        New_Graph[a].append((y,b))
        New_Graph[b].append((y,a))
    else:
        New_Graph[a].append((x,b))
        New_Graph[b].append((x,a))
#print(New_Graph)
RD, RPREV = dijkstra_heap2(N-1,New_Graph)
#print(RD)
ans += RD[0]
print(ans)
0