結果

問題 No.859 路線A、路線B、路線C
ユーザー convexineqconvexineq
提出日時 2021-04-04 19:56:29
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 919 bytes
コンパイル時間 552 ms
コンパイル使用メモリ 86,932 KB
実行使用メモリ 71,540 KB
最終ジャッジ日時 2023-08-27 21:21:20
合計ジャッジ時間 3,116 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
71,160 KB
testcase_01 AC 81 ms
71,076 KB
testcase_02 AC 79 ms
71,276 KB
testcase_03 AC 82 ms
71,388 KB
testcase_04 AC 83 ms
71,304 KB
testcase_05 AC 81 ms
71,064 KB
testcase_06 AC 82 ms
71,228 KB
testcase_07 AC 81 ms
71,424 KB
testcase_08 AC 82 ms
71,140 KB
testcase_09 AC 79 ms
71,464 KB
testcase_10 AC 80 ms
71,336 KB
testcase_11 WA -
testcase_12 AC 82 ms
71,364 KB
testcase_13 AC 80 ms
71,148 KB
testcase_14 AC 81 ms
71,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *
def dijkstra(g,start):
    n = len(g)
    INF = 1<<61
    dist = [INF]*(n) #startからの最短距離
    #pending = n-1 #未確定の点の個数
    dist[start] = 0
    q = [(0,start)] #(そこまでの距離、点)
    while q:# and pending:
        dv,v = heappop(q)
        if dist[v] < dv: continue
        for to, cost in g[v]:
            if dv + cost < dist[to]:
                dist[to] = dv + cost
                heappush(q, (dist[to], to))
    return dist

x,y,z = map(int, input().split())
s,a = input().split()
t,b = input().split()
g = [[] for _ in range(8)]
for p,q,r in[(0,1,1),(1,2,1),(0,2,1),(3,4,1),(3,5,1),(4,5,1),(0,3,x-1),(2,5,z-1),(1,4,y-1)]:
    g[p].append((q,r))
    g[q].append((p,r))

a = int(a)
b = int(b)
c = "ABC".find(s)
g[6] = [(c,a-1),(c+3,[x,y,z][c]-a)]
c = "ABC".find(t)
g[c].append((7,b-1))
g[c+3].append((7,[x,y,z][c]-b))

dist = dijkstra(g,6)
print(dist[7])
0