結果

問題 No.1545 [Cherry 2nd Tune N] Anthem
ユーザー mkawa2mkawa2
提出日時 2021-06-11 22:14:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,425 ms / 3,000 ms
コード長 1,520 bytes
コンパイル時間 378 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 172,752 KB
最終ジャッジ日時 2024-05-08 18:06:14
合計ジャッジ時間 24,632 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,736 KB
testcase_01 AC 42 ms
52,736 KB
testcase_02 AC 43 ms
52,864 KB
testcase_03 AC 42 ms
53,120 KB
testcase_04 AC 174 ms
93,952 KB
testcase_05 AC 398 ms
109,312 KB
testcase_06 AC 292 ms
93,568 KB
testcase_07 AC 350 ms
101,632 KB
testcase_08 AC 655 ms
105,728 KB
testcase_09 AC 258 ms
86,144 KB
testcase_10 AC 180 ms
97,024 KB
testcase_11 AC 237 ms
96,128 KB
testcase_12 AC 290 ms
105,728 KB
testcase_13 AC 144 ms
87,296 KB
testcase_14 AC 141 ms
90,496 KB
testcase_15 AC 97 ms
80,896 KB
testcase_16 AC 175 ms
99,712 KB
testcase_17 AC 182 ms
81,664 KB
testcase_18 AC 301 ms
109,056 KB
testcase_19 AC 252 ms
93,184 KB
testcase_20 AC 225 ms
83,328 KB
testcase_21 AC 218 ms
108,928 KB
testcase_22 AC 234 ms
109,696 KB
testcase_23 AC 272 ms
90,368 KB
testcase_24 AC 115 ms
77,568 KB
testcase_25 AC 140 ms
77,952 KB
testcase_26 AC 59 ms
64,128 KB
testcase_27 AC 127 ms
77,184 KB
testcase_28 AC 148 ms
78,080 KB
testcase_29 AC 133 ms
77,568 KB
testcase_30 AC 120 ms
77,696 KB
testcase_31 AC 145 ms
78,208 KB
testcase_32 AC 123 ms
77,184 KB
testcase_33 AC 149 ms
78,080 KB
testcase_34 AC 152 ms
78,336 KB
testcase_35 AC 190 ms
79,104 KB
testcase_36 AC 165 ms
78,208 KB
testcase_37 AC 108 ms
77,056 KB
testcase_38 AC 142 ms
78,080 KB
testcase_39 AC 124 ms
77,184 KB
testcase_40 AC 120 ms
77,824 KB
testcase_41 AC 108 ms
76,800 KB
testcase_42 AC 150 ms
78,592 KB
testcase_43 AC 147 ms
78,208 KB
testcase_44 AC 70 ms
70,400 KB
testcase_45 AC 47 ms
59,520 KB
testcase_46 AC 161 ms
78,336 KB
testcase_47 AC 177 ms
79,616 KB
testcase_48 AC 233 ms
85,760 KB
testcase_49 AC 285 ms
82,048 KB
testcase_50 AC 451 ms
88,704 KB
testcase_51 AC 129 ms
77,312 KB
testcase_52 AC 431 ms
87,936 KB
testcase_53 AC 221 ms
82,944 KB
testcase_54 AC 110 ms
77,312 KB
testcase_55 AC 376 ms
86,784 KB
testcase_56 AC 70 ms
71,168 KB
testcase_57 AC 349 ms
82,944 KB
testcase_58 AC 242 ms
82,432 KB
testcase_59 AC 137 ms
77,824 KB
testcase_60 AC 92 ms
78,080 KB
testcase_61 AC 184 ms
78,464 KB
testcase_62 AC 284 ms
81,152 KB
testcase_63 AC 210 ms
79,104 KB
testcase_64 AC 2,425 ms
172,752 KB
testcase_65 AC 144 ms
78,080 KB
testcase_66 AC 269 ms
132,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LI1(): return list(map(int1, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 10**16
# md = 998244353
# md = 10**9+7

from heapq import *

n, s, t, k = LI()
s, t = s-1, t-1
xx = LI()
m = II()
to = [[] for _ in range(n)]
for _ in range(m):
    u, v, c = LI1()
    to[u].append((v, c+1))

dist = [[inf]*k for _ in range(n)]
pre = [[(-1, -1) for _ in range(k)] for _ in range(n)]
dist[s][0] = xx[s]
hp = [(xx[s], s, 0)]
while hp:
    d, u, f = heappop(hp)
    if u == t and f == k-1:
        print("Possible")
        print(d)
        pp = []
        while u != -1:
            pp.append(u+1)
            u, f = pre[u][f]
        print(len(pp))
        print(*pp[::-1])
        exit()
    if d > dist[u][f]: continue
    for v, c in to[u]:
        nd = d+c+xx[v]
        nf = min(f+1, k-1)
        if nd >= dist[v][nf]: continue
        dist[v][nf] = nd
        pre[v][nf] = (u, f)
        heappush(hp,(nd,v,nf))

print("Impossible")
0