結果

問題 No.848 なかよし旅行
ユーザー hedwig100hedwig100
提出日時 2020-04-17 16:16:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,356 bytes
コンパイル時間 248 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 51,940 KB
最終ジャッジ日時 2024-04-14 12:40:15
合計ジャッジ時間 28,048 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,273 ms
51,684 KB
testcase_01 AC 31 ms
11,008 KB
testcase_02 AC 31 ms
10,880 KB
testcase_03 AC 31 ms
11,008 KB
testcase_04 AC 32 ms
11,008 KB
testcase_05 AC 32 ms
11,136 KB
testcase_06 AC 33 ms
11,008 KB
testcase_07 AC 31 ms
11,136 KB
testcase_08 AC 65 ms
11,008 KB
testcase_09 AC 65 ms
11,392 KB
testcase_10 AC 63 ms
11,008 KB
testcase_11 AC 1,360 ms
18,560 KB
testcase_12 AC 1,736 ms
21,120 KB
testcase_13 TLE -
testcase_14 AC 1,599 ms
13,952 KB
testcase_15 AC 1,770 ms
24,448 KB
testcase_16 TLE -
testcase_17 AC 1,629 ms
26,368 KB
testcase_18 AC 1,318 ms
17,664 KB
testcase_19 AC 1,440 ms
16,640 KB
testcase_20 TLE -
testcase_21 AC 1,732 ms
30,208 KB
testcase_22 AC 713 ms
31,872 KB
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

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
    
    for i in range(n):
        for j in range(n):
            if d0[i] + d0[j] + max(dp[i] + dp[j],dq[i] + dq[j]) <= t:
                ans = max(ans,t - max(dp[i] + dp[j],dq[i] + dq[j]))
    print(ans)

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