結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,476 KB
testcase_01 AC 75 ms
71,432 KB
testcase_02 WA -
testcase_03 AC 637 ms
116,132 KB
testcase_04 AC 823 ms
135,596 KB
testcase_05 AC 594 ms
116,488 KB
testcase_06 AC 780 ms
130,504 KB
testcase_07 AC 725 ms
125,968 KB
testcase_08 AC 639 ms
115,876 KB
testcase_09 AC 735 ms
128,780 KB
testcase_10 WA -
testcase_11 AC 785 ms
130,372 KB
testcase_12 AC 810 ms
131,532 KB
testcase_13 AC 693 ms
123,652 KB
testcase_14 AC 738 ms
126,496 KB
testcase_15 AC 687 ms
124,716 KB
testcase_16 AC 809 ms
137,196 KB
testcase_17 AC 740 ms
127,472 KB
testcase_18 AC 684 ms
122,164 KB
testcase_19 AC 779 ms
130,548 KB
testcase_20 AC 770 ms
132,456 KB
testcase_21 AC 733 ms
127,772 KB
testcase_22 AC 769 ms
133,736 KB
testcase_23 AC 729 ms
125,432 KB
testcase_24 AC 766 ms
132,308 KB
testcase_25 AC 815 ms
134,192 KB
testcase_26 AC 767 ms
128,676 KB
testcase_27 AC 771 ms
129,820 KB
testcase_28 AC 623 ms
118,456 KB
testcase_29 WA -
testcase_30 AC 824 ms
132,660 KB
testcase_31 AC 807 ms
133,328 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 646 ms
126,252 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))
#print(Used)
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