結果

問題 No.848 なかよし旅行
ユーザー hedwig100hedwig100
提出日時 2020-04-17 16:17:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 520 ms / 2,000 ms
コード長 1,356 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 87,308 KB
実行使用メモリ 104,364 KB
最終ジャッジ日時 2023-08-07 20:01:32
合計ジャッジ時間 7,472 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 520 ms
104,364 KB
testcase_01 AC 78 ms
71,516 KB
testcase_02 AC 75 ms
71,280 KB
testcase_03 AC 76 ms
71,344 KB
testcase_04 AC 78 ms
71,436 KB
testcase_05 AC 75 ms
71,360 KB
testcase_06 AC 91 ms
75,944 KB
testcase_07 AC 77 ms
71,396 KB
testcase_08 AC 124 ms
77,944 KB
testcase_09 AC 146 ms
79,028 KB
testcase_10 AC 126 ms
77,400 KB
testcase_11 AC 233 ms
81,184 KB
testcase_12 AC 261 ms
82,352 KB
testcase_13 AC 264 ms
83,908 KB
testcase_14 AC 207 ms
79,536 KB
testcase_15 AC 271 ms
83,372 KB
testcase_16 AC 339 ms
88,544 KB
testcase_17 AC 268 ms
84,676 KB
testcase_18 AC 228 ms
81,240 KB
testcase_19 AC 227 ms
80,700 KB
testcase_20 AC 185 ms
79,132 KB
testcase_21 AC 295 ms
86,608 KB
testcase_22 AC 241 ms
87,556 KB
testcase_23 AC 194 ms
78,228 KB
testcase_24 AC 76 ms
71,072 KB
testcase_25 AC 355 ms
89,300 KB
testcase_26 AC 75 ms
71,356 KB
testcase_27 AC 75 ms
71,288 KB
testcase_28 AC 75 ms
71,280 KB
testcase_29 AC 77 ms
71,156 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
    
    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