結果
| 問題 |
No.848 なかよし旅行
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-01-31 04:57:59 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,640 bytes |
| コンパイル時間 | 207 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 130,432 KB |
| 最終ジャッジ日時 | 2024-06-28 15:53:25 |
| 合計ジャッジ時間 | 6,919 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 4 |
| other | TLE * 1 -- * 25 |
ソースコード
#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 i in range(N):
cost[i][i] = 0
# ワーシャルフロイド
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(i, 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 = T - max(cost[i][P] + cost[P][j], cost[i][Q] + cost[Q][j])
max_t = max(max_t, t)
print(max_t)
if __name__ == '__main__':
main()