結果
| 問題 | 
                            No.1545 [Cherry 2nd Tune N] Anthem
                             | 
                    
| コンテスト | |
| ユーザー | 
                            👑  Kazun
                         | 
                    
| 提出日時 | 2021-05-20 00:32:04 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 1,058 ms / 3,000 ms | 
| コード長 | 2,570 bytes | 
| コンパイル時間 | 447 ms | 
| コンパイル使用メモリ | 82,376 KB | 
| 実行使用メモリ | 198,864 KB | 
| 最終ジャッジ日時 | 2024-12-14 21:37:26 | 
| 合計ジャッジ時間 | 22,888 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 67 | 
ソースコード
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)]
A=[]; B=[]; Y=[]
for _ in range(M):
    a,b,y=map(int,input().split())
    E[a].append((b,y))
    A.append(a)
    B.append(b)
    Y.append(y)
#==================================================
#Validator
assert 1<=N<=10**5,"Nが制約違反 (N={})".format(N)
assert 1<=S<=N,"Sが制約違反 (S={}, N={})".format(S,N)
assert 1<=T<=N,"Tが制約違反 (T={}, N={})".format(T,N)
assert 1<=K<=3*10**4,"Kが制約違反 (K={})".format(K)
assert 1<=M<=min(N*N,2*10**5),"M が制約違反 (M={}, N^2={})".format(M,N*N)
for i in range(M):
    assert 1<=A[i]<=N, "A_{}が制約違反 (A_{}={})".format(i+1,i+1,A[i])
    assert 1<=B[i]<=N, "B_{}が制約違反 (B_{}={})".format(i+1,i+1,B[i])
assert len(set([(a,b) for a,b in zip(A,B)]))==M,"(A,B) に重複あり"
for i in range(M):
    assert 1<=Y[i]<=10**9,"Y_{}が制約違反 (Y_{}={})".format(i+1,i+1,Y[i])
Type_A=(1<=N<=10**5) and (1<=K<=10)
Type_B=(1<=N<=130) and (1<=K<=130)
Type_C=(1<=N<=10) and (1<=K<=3*10**4)
print("[A]: {}".format(Type_A),file=sys.stderr)
print("[B]: {}".format(Type_B),file=sys.stderr)
print("[C]: {}".format(Type_C),file=sys.stderr)
assert Type_A or Type_B or Type_C,"[A],[B],[C] のいずれも満たさない (N={}, K={})".format(N,K)
#==================================================
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")
            
            
            
        
            
Kazun