結果
問題 | No.1545 [Cherry 2nd Tune N] Anthem |
ユーザー |
|
提出日時 | 2021-06-12 16:20:22 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,998 ms / 3,000 ms |
コード長 | 913 bytes |
コンパイル時間 | 255 ms |
コンパイル使用メモリ | 82,428 KB |
実行使用メモリ | 229,924 KB |
最終ジャッジ日時 | 2024-12-17 13:21:49 |
合計ジャッジ時間 | 25,873 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 67 |
ソースコード
from heapq import *n,s,t,k = map(int,input().split())s,t = s-1,t-1X = list(map(int,input().split()))m = int(input())e = [[] for i in range(n)]for i in range(m):a,b,y = map(int,input().split())e[a-1].append((b-1,y))inf = 10**20dis = [[inf]*k for i in range(n)]par = [[[-1,-1]for _ in range(k) ]for i in range(n)]dis[s][0] = X[s]h = [(X[s],s,0)]while h:d,now,l = heappop(h)if now == t and l == k-1:print("Possible")print(d)ans = []while now != -1:ans.append(now+1)now,l = par[now][l]print(len(ans))print(*ans[::-1])exit()if d != dis[now][l]:continuefor nex, y in e[now]:nd = d+y+X[nex]nl = min(l+1,k-1)if dis[nex][nl] > nd:dis[nex][nl] = ndheappush(h,(nd,nex,nl))par[nex][nl] = [now,l]print("Impossible")