結果

問題 No.848 なかよし旅行
ユーザー hedwig100hedwig100
提出日時 2020-04-16 23:58:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,263 bytes
コンパイル時間 486 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 44,780 KB
最終ジャッジ日時 2024-04-14 07:12:38
合計ジャッジ時間 10,037 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,299 ms
44,780 KB
testcase_01 AC 33 ms
10,880 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 33 ms
11,008 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 32 ms
10,880 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 413 ms
25,088 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 52 ms
12,032 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 32 ms
11,008 KB
testcase_25 WA -
testcase_26 AC 33 ms
10,880 KB
testcase_27 AC 33 ms
10,880 KB
testcase_28 AC 32 ms
10,880 KB
testcase_29 AC 32 ms
10,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10 ** 9 + 7
INF = 10 ** 12
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  itertools import permutations
from heapq import heapify,heappop,heappush

def dijkstra(G,s = 0): #sを始点とした最短経を求める
    n = len(G)
    dist = [INF] * n
    dist[s] = 0

    q = [(0,s)]
    heapify(q)

    while q:
        d,v = heappop(q)
        if dist[v] < d:
            continue
        for e,cost in G[v]:
            if dist[e] > dist[v] + cost:
                dist[e] = dist[v] + cost
                heappush(q,(dist[e],e))
    
    return dist

def main():
    n,m,p,q,t = map(int,input().split())
    p -= 1
    q -= 1
    G = [[] for _ in range(n)]
    for _ in range(m):
        a,b,c = map(int,input().split())
        a -= 1
        b -= 1
        G[a].append((b,c))
        G[b].append((a,c))
    
    d0 = dijkstra(G)
    dp = dijkstra(G,p)
    dq = dijkstra(G,q)
    if d0[p] + dp[q] + dq[0] <= t:
        print(t)
        return

    ans = -1
    for i in range(n):
        if 2 * (d0[i] + dp[i] + dq[i]) <= t:
            print(t)
            return
        if 2 * (max(dp[i],dq[i]) + d0[i]) <= t:
            ans = max(ans,t - 2 * max(dp[i],dq[i]))
    print(ans)

if __name__ =='__main__':
    main()  
0