結果

問題 No.848 なかよし旅行
ユーザー tcltktcltk
提出日時 2021-01-31 04:53:03
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,587 bytes
コンパイル時間 410 ms
コンパイル使用メモリ 87,172 KB
実行使用メモリ 127,396 KB
最終ジャッジ日時 2023-09-11 01:14:42
合計ジャッジ時間 7,176 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 #

#region Header
#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq

def input():
    return sys.stdin.readline()[:-1]

sys.setrecursionlimit(1000000)
#endregion

# _INPUT = """5 6 4 5 8
# 1 2 2
# 2 5 3
# 2 4 1
# 3 4 3
# 1 3 2
# 3 5 1
# """
# sys.stdin = io.StringIO(_INPUT)


def main():
    N, M, P, Q, T = map(int, input().split())
    P -= 1
    Q -= 1
    INF = 10**10
    cost = [[INF] * N for _ in range(N)]
    for _ in range(M):
        a, b, c = map(int, input().split())
        cost[a-1][b-1] = c
        cost[b-1][a-1] = c

    # ワーシャルフロイド
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if cost[i][k] != INF and cost[k][j] != INF:
                    cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])

    if cost[0][P] + cost[P][Q] + cost[Q][0] <= T:
        print(T)
    
    else:
        max_t = -1
        for i in range(N):
            for j in range(N):
                # 0 -> i -> P -> j -> 0
                # 0 -> i -> Q -> j -> 0
                t_total1 = cost[0][i] + cost[i][P] + cost[P][j] + cost[j][0]
                t_total2 = cost[0][i] + cost[i][Q] + cost[Q][j] + cost[j][0]
                if t_total1 <= T and t_total2 <= T:
                    t = cost[0][i] + cost[j][0] + (T - max(t_total1, t_total2))
                    max_t = max(max_t, t)
        print(max_t)


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