結果

問題 No.848 なかよし旅行
ユーザー simamumusimamumu
提出日時 2019-07-05 21:56:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,314 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 13,056 KB
実行使用メモリ 66,304 KB
最終ジャッジ日時 2024-04-16 07:17:18
合計ジャッジ時間 6,773 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

def Dijkustra(lines,N,s):
    weight = [INF]*N
    weight[s] = 0

    def search (s,w_0,q,weight): #s->t
    	for line in list(lines[s]):
    		t = line[0]
    		w = w_0 + line[1]
    		if weight[t] > w:
    			heapq.heappush(q, [w,t])
    			weight[t] = w

    q = [[0,s]]
    heapq.heapify(q)
    while q:
    	w,n = heapq.heappop(q)
    	search(n,w,q,weight)

    return weight

N,M,P,Q,T = inpl()
S,P,Q = 0,P-1,Q-1
lines = defaultdict(set)
for _ in range(M):
    a,b,c = inpl()
    a,b = a-1,b-1
    lines[a].add((b,c))
    lines[b].add((a,c))

weight_S = Dijkustra(lines,N,S)
weight_P = Dijkustra(lines,N,P)
weight_Q = Dijkustra(lines,N,Q)

SP = weight_S[P]
SQ = weight_S[Q]
PQ = weight_P[Q]

if SP + PQ + SQ <= T:
    print(T)
elif SP*2 > T or SQ*2 > T:
    print(-1)
else:
    ans = 0
    for X in range(N):
        SX = weight_S[X]
        PX,QX = weight_P[X], weight_Q[X]
        #print(X,SX,PX,QX)
        d = max(PX,QX)
        if d*2 + SX*2 <= T:
            ans = max(ans,T-d*2)
    print(ans)
0