結果

問題 No.1545 [Cherry 2nd Tune N] Anthem
ユーザー 👑 KazunKazun
提出日時 2021-04-03 19:57:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,028 ms / 3,000 ms
コード長 1,375 bytes
コンパイル時間 417 ms
コンパイル使用メモリ 87,268 KB
実行使用メモリ 182,676 KB
最終ジャッジ日時 2023-08-21 09:27:48
合計ジャッジ時間 29,221 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,536 KB
testcase_01 AC 76 ms
71,380 KB
testcase_02 AC 76 ms
70,984 KB
testcase_03 AC 74 ms
71,556 KB
testcase_04 AC 176 ms
96,904 KB
testcase_05 AC 438 ms
117,956 KB
testcase_06 AC 324 ms
100,016 KB
testcase_07 AC 383 ms
108,280 KB
testcase_08 AC 676 ms
113,684 KB
testcase_09 AC 322 ms
88,736 KB
testcase_10 AC 204 ms
100,608 KB
testcase_11 AC 248 ms
99,420 KB
testcase_12 AC 295 ms
106,176 KB
testcase_13 AC 170 ms
88,668 KB
testcase_14 AC 167 ms
96,216 KB
testcase_15 AC 121 ms
83,284 KB
testcase_16 AC 190 ms
102,776 KB
testcase_17 AC 235 ms
83,424 KB
testcase_18 AC 306 ms
112,948 KB
testcase_19 AC 282 ms
96,156 KB
testcase_20 AC 348 ms
87,596 KB
testcase_21 AC 227 ms
110,544 KB
testcase_22 AC 242 ms
112,444 KB
testcase_23 AC 340 ms
95,068 KB
testcase_24 AC 168 ms
79,600 KB
testcase_25 AC 195 ms
79,620 KB
testcase_26 AC 108 ms
77,840 KB
testcase_27 AC 165 ms
78,492 KB
testcase_28 AC 191 ms
80,116 KB
testcase_29 AC 190 ms
80,204 KB
testcase_30 AC 186 ms
79,792 KB
testcase_31 AC 174 ms
79,284 KB
testcase_32 AC 155 ms
79,256 KB
testcase_33 AC 213 ms
80,332 KB
testcase_34 AC 196 ms
80,108 KB
testcase_35 AC 231 ms
80,740 KB
testcase_36 AC 230 ms
80,848 KB
testcase_37 AC 148 ms
78,504 KB
testcase_38 AC 185 ms
79,036 KB
testcase_39 AC 162 ms
78,796 KB
testcase_40 AC 190 ms
79,784 KB
testcase_41 AC 147 ms
78,700 KB
testcase_42 AC 214 ms
80,984 KB
testcase_43 AC 224 ms
80,300 KB
testcase_44 AC 105 ms
78,572 KB
testcase_45 AC 80 ms
75,160 KB
testcase_46 AC 197 ms
80,928 KB
testcase_47 AC 209 ms
83,792 KB
testcase_48 AC 279 ms
90,248 KB
testcase_49 AC 266 ms
86,956 KB
testcase_50 AC 359 ms
94,724 KB
testcase_51 AC 178 ms
78,856 KB
testcase_52 AC 359 ms
94,180 KB
testcase_53 AC 232 ms
87,032 KB
testcase_54 AC 142 ms
79,220 KB
testcase_55 AC 326 ms
92,480 KB
testcase_56 AC 104 ms
78,572 KB
testcase_57 AC 311 ms
86,636 KB
testcase_58 AC 263 ms
87,352 KB
testcase_59 AC 176 ms
80,992 KB
testcase_60 AC 121 ms
78,860 KB
testcase_61 AC 230 ms
81,828 KB
testcase_62 AC 268 ms
84,516 KB
testcase_63 AC 258 ms
82,296 KB
testcase_64 AC 1,028 ms
182,676 KB
testcase_65 AC 190 ms
80,404 KB
testcase_66 AC 319 ms
148,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Heap_Point:
        def __init__(self,x,d):
            self.d=d
            self.x=x

        def __str__(self):
            return "(point:{}, dist:{})".format(self.x,self.d)

        def __repr__(self):
            return str(self)

        def __lt__(self,other):
            return self.d<other.d

        def __iter__(self):
            yield from (self.x,self.d)
#================================================
import sys
from heapq import heapify,heappop,heappush

input=sys.stdin.readline
N,S,T,K=map(int,input().split())
X=["*"]+list(map(int,input().split()))

M=int(input())
E=[[] for _ in range(N+1)]
for _ in range(M):
    A,B,Y=map(int,input().split())
    E[A].append((B,Y))

inf=float("inf")

DP=[[inf]*(K+1) for _ in range(N+1)]
DP[S][1]=X[S]

Reverse=[[(0,0) for _ in range(K+1)] for _ in range(N+1)]

Q=[Heap_Point((S,1),0)]
heapify(Q)

while Q:
    (x,k),d=heappop(Q)

    if DP[x][k]<d:
        continue

    if x==T and k==K:
        break

    l=min(k+1,K)
    for y,m in E[x]:
        if DP[x][k]+m+X[y]<DP[y][l]:
            DP[y][l]=DP[x][k]+m+X[y]
            Reverse[y][l]=(x,k)
            heappush(Q,Heap_Point((y,l),DP[y][l]))

V=DP[T][K]

if V<inf:
    x,k=T,K
    P=[]

    while k>0:
        P.append(x)
        x,k=Reverse[x][k]

    print("Possible")
    print(V)
    print(len(P))
    print(*P[::-1])
else:
    print("Impossible")
0