結果

問題 No.1545 [Cherry 2nd Tune N] Anthem
ユーザー mkawa2mkawa2
提出日時 2021-06-11 22:14:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,745 ms / 3,000 ms
コード長 1,520 bytes
コンパイル時間 410 ms
コンパイル使用メモリ 86,744 KB
実行使用メモリ 173,952 KB
最終ジャッジ日時 2023-08-21 12:48:40
合計ジャッジ時間 26,870 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,084 KB
testcase_01 AC 74 ms
71,280 KB
testcase_02 AC 76 ms
71,384 KB
testcase_03 AC 74 ms
71,372 KB
testcase_04 AC 178 ms
93,872 KB
testcase_05 AC 402 ms
111,264 KB
testcase_06 AC 295 ms
94,800 KB
testcase_07 AC 340 ms
102,556 KB
testcase_08 AC 623 ms
109,076 KB
testcase_09 AC 271 ms
86,612 KB
testcase_10 AC 189 ms
97,672 KB
testcase_11 AC 236 ms
96,820 KB
testcase_12 AC 275 ms
106,300 KB
testcase_13 AC 158 ms
87,812 KB
testcase_14 AC 163 ms
94,884 KB
testcase_15 AC 118 ms
81,372 KB
testcase_16 AC 185 ms
99,704 KB
testcase_17 AC 198 ms
83,136 KB
testcase_18 AC 292 ms
109,444 KB
testcase_19 AC 260 ms
94,024 KB
testcase_20 AC 235 ms
84,712 KB
testcase_21 AC 220 ms
109,456 KB
testcase_22 AC 231 ms
109,964 KB
testcase_23 AC 279 ms
92,384 KB
testcase_24 AC 137 ms
78,496 KB
testcase_25 AC 164 ms
79,212 KB
testcase_26 AC 91 ms
76,476 KB
testcase_27 AC 149 ms
78,744 KB
testcase_28 AC 171 ms
79,348 KB
testcase_29 AC 155 ms
79,188 KB
testcase_30 AC 143 ms
79,084 KB
testcase_31 AC 169 ms
79,420 KB
testcase_32 AC 147 ms
78,428 KB
testcase_33 AC 170 ms
79,580 KB
testcase_34 AC 173 ms
79,772 KB
testcase_35 AC 214 ms
80,384 KB
testcase_36 AC 183 ms
79,080 KB
testcase_37 AC 126 ms
78,080 KB
testcase_38 AC 162 ms
78,444 KB
testcase_39 AC 147 ms
78,688 KB
testcase_40 AC 139 ms
78,236 KB
testcase_41 AC 129 ms
78,000 KB
testcase_42 AC 168 ms
79,492 KB
testcase_43 AC 169 ms
79,436 KB
testcase_44 AC 97 ms
76,524 KB
testcase_45 AC 79 ms
75,480 KB
testcase_46 AC 180 ms
79,460 KB
testcase_47 AC 195 ms
80,844 KB
testcase_48 AC 247 ms
87,792 KB
testcase_49 AC 298 ms
84,036 KB
testcase_50 AC 454 ms
89,828 KB
testcase_51 AC 153 ms
78,516 KB
testcase_52 AC 437 ms
89,348 KB
testcase_53 AC 235 ms
83,884 KB
testcase_54 AC 132 ms
78,332 KB
testcase_55 AC 384 ms
87,816 KB
testcase_56 AC 99 ms
78,160 KB
testcase_57 AC 361 ms
84,216 KB
testcase_58 AC 253 ms
83,812 KB
testcase_59 AC 162 ms
79,404 KB
testcase_60 AC 111 ms
78,696 KB
testcase_61 AC 202 ms
79,712 KB
testcase_62 AC 303 ms
82,040 KB
testcase_63 AC 231 ms
80,204 KB
testcase_64 AC 1,745 ms
173,952 KB
testcase_65 AC 164 ms
79,560 KB
testcase_66 AC 265 ms
135,732 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