結果

問題 No.2805 Go to School
ユーザー mattu34mattu34
提出日時 2024-07-12 21:50:41
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 3,050 bytes
コンパイル時間 235 ms
コンパイル使用メモリ 82,456 KB
実行使用メモリ 174,732 KB
最終ジャッジ日時 2024-07-12 21:51:07
合計ジャッジ時間 22,953 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 170 ms
88,644 KB
testcase_01 AC 155 ms
88,764 KB
testcase_02 AC 161 ms
88,872 KB
testcase_03 AC 151 ms
88,948 KB
testcase_04 AC 979 ms
117,944 KB
testcase_05 AC 574 ms
105,404 KB
testcase_06 AC 564 ms
105,024 KB
testcase_07 AC 606 ms
115,380 KB
testcase_08 AC 758 ms
107,160 KB
testcase_09 AC 288 ms
99,408 KB
testcase_10 AC 512 ms
137,792 KB
testcase_11 AC 482 ms
114,004 KB
testcase_12 AC 471 ms
112,028 KB
testcase_13 AC 207 ms
96,436 KB
testcase_14 AC 176 ms
88,612 KB
testcase_15 AC 160 ms
88,768 KB
testcase_16 AC 163 ms
88,616 KB
testcase_17 AC 1,024 ms
114,848 KB
testcase_18 AC 632 ms
105,992 KB
testcase_19 AC 1,389 ms
126,300 KB
testcase_20 AC 1,185 ms
144,844 KB
testcase_21 AC 726 ms
116,048 KB
testcase_22 AC 1,105 ms
121,608 KB
testcase_23 AC 992 ms
120,216 KB
testcase_24 AC 813 ms
114,212 KB
testcase_25 TLE -
testcase_26 AC 472 ms
142,140 KB
testcase_27 AC 187 ms
101,456 KB
testcase_28 AC 189 ms
97,332 KB
testcase_29 AC 286 ms
130,424 KB
testcase_30 AC 757 ms
112,184 KB
testcase_31 AC 1,469 ms
167,552 KB
testcase_32 TLE -
testcase_33 AC 159 ms
89,388 KB
testcase_34 AC 186 ms
89,364 KB
testcase_35 AC 577 ms
108,672 KB
testcase_36 AC 499 ms
110,020 KB
testcase_37 AC 395 ms
118,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
import sys
import heapq
from heapq import heapify, heappop, heappush
import bisect
import itertools
from functools import lru_cache
from types import GeneratorType
from fractions import Fraction
import math
import copy
import random

# import numpy as np

# sys.setrecursionlimit(int(1e7))
# @lru_cache(maxsize=None) # CPython特化
# @bootstrap # PyPy特化(こっちのほうが速い) yield dfs(), yield Noneを忘れずに


def bootstrap(f, stack=[]):  # yield
    def wrappedfunc(*args, **kwargs):
        if stack:
            return f(*args, **kwargs)
        else:
            to = f(*args, **kwargs)
            while True:
                if type(to) is GeneratorType:
                    stack.append(to)
                    to = next(to)
                else:
                    stack.pop()
                    if not stack:
                        break
                    to = stack[-1].send(to)
            return to

    return wrappedfunc


dxdy1 = ((0, 1), (0, -1), (1, 0), (-1, 0))  # 上下右左
dxdy2 = (
    (0, 1),
    (0, -1),
    (1, 0),
    (-1, 0),
    (1, 1),
    (-1, -1),
    (1, -1),
    (-1, 1),
)  # 8方向すべて
dxdy3 = ((0, 1), (1, 0))  # 右 or 下
dxdy4 = ((1, 1), (1, -1), (-1, 1), (-1, -1))  # 斜め
INF = float("inf")
_INF = 1 << 60
MOD = 998244353
mod = 998244353
MOD2 = 10**9 + 7
mod2 = 10**9 + 7
# memo : len([a,b,...,z])==26
# memo : 2^20 >= 10^6
# 小数の計算を避ける : x/y -> (x*big)//y  ex:big=10**9
# @:小さい文字, ~:大きい文字,None: 空の文字列
# ユークリッドの互除法:gcd(x,y)=gcd(x,y-x)
# memo : d 桁以下の p 進表記を用いると p^d-1 以下のすべての
#        非負整数を表現することができる
# memo : (X,Y) -> (X+Y,X−Y) <=> 点を原点を中心に45度回転し、√2倍に拡大
# memo : (x,y)のx正から見た偏角をラジアンで(-πからπ]: math.atan2(y, x)
# memo : a < bのとき ⌊a⌋ ≦ ⌊b⌋

input = lambda: sys.stdin.readline().rstrip()
mi = lambda: map(int, input().split())
li = lambda: list(mi())
ii = lambda: int(input())
py = lambda: print("Yes")
pn = lambda: print("No")
pf = lambda: print("First")
ps = lambda: print("Second")

INF = 10**15
N, M, L, S, E = mi()
TT = S + E
adj = [[] for _ in range(N)]
for _ in range(M):
    a, b, t = mi()
    a -= 1
    b -= 1
    adj[a].append((b, t))
    adj[b].append((a, t))
dist = [[INF] * 2 for _ in range(N)]
T = li()
T = [t - 1 for t in T]
T = set(T)
pq = []
heappush(pq, (0, 0, 0))
while pq:
    t, node, s = heappop(pq)
    if dist[node][s] < t:
        continue
    dist[node][s] = t
    if node in T and t < TT and s == 0:
        wait = max(0, S - t)
        dist[node][1] = t + wait + 1
        heappush(pq, (dist[node][1], node, 1))
    for nxt, w in adj[node]:
        if dist[nxt][s] <= t + w:
            continue
        if s == 0 and t + w >= TT:
            continue
        dist[nxt][s] = t + w
        heappush(pq, (dist[nxt][s], nxt, s))

if dist[-1][1] == INF:
    print(-1)
else:
    print(dist[-1][1])
0