結果

問題 No.1545 [Cherry 2nd Tune N] Anthem
ユーザー ygd.ygd.
提出日時 2021-06-15 23:31:02
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,436 bytes
コンパイル時間 416 ms
コンパイル使用メモリ 86,976 KB
実行使用メモリ 144,404 KB
最終ジャッジ日時 2023-08-27 20:27:19
合計ジャッジ時間 31,455 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
71,408 KB
testcase_01 AC 99 ms
71,600 KB
testcase_02 WA -
testcase_03 AC 95 ms
71,412 KB
testcase_04 AC 208 ms
87,248 KB
testcase_05 RE -
testcase_06 WA -
testcase_07 AC 263 ms
90,616 KB
testcase_08 RE -
testcase_09 WA -
testcase_10 AC 224 ms
92,744 KB
testcase_11 WA -
testcase_12 RE -
testcase_13 WA -
testcase_14 RE -
testcase_15 WA -
testcase_16 RE -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 411 ms
87,444 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 214 ms
82,516 KB
testcase_25 AC 213 ms
80,336 KB
testcase_26 AC 115 ms
77,356 KB
testcase_27 AC 195 ms
80,040 KB
testcase_28 AC 219 ms
81,624 KB
testcase_29 AC 237 ms
81,744 KB
testcase_30 AC 222 ms
81,696 KB
testcase_31 AC 237 ms
82,008 KB
testcase_32 AC 181 ms
78,744 KB
testcase_33 AC 264 ms
83,048 KB
testcase_34 AC 248 ms
81,940 KB
testcase_35 AC 293 ms
82,960 KB
testcase_36 AC 291 ms
82,792 KB
testcase_37 AC 172 ms
79,136 KB
testcase_38 AC 252 ms
81,432 KB
testcase_39 AC 186 ms
78,912 KB
testcase_40 AC 224 ms
80,928 KB
testcase_41 AC 169 ms
78,800 KB
testcase_42 WA -
testcase_43 AC 248 ms
82,440 KB
testcase_44 AC 122 ms
79,340 KB
testcase_45 AC 96 ms
71,844 KB
testcase_46 AC 246 ms
87,700 KB
testcase_47 AC 251 ms
87,964 KB
testcase_48 AC 315 ms
97,316 KB
testcase_49 AC 398 ms
91,204 KB
testcase_50 AC 543 ms
97,556 KB
testcase_51 AC 237 ms
102,452 KB
testcase_52 AC 554 ms
97,440 KB
testcase_53 AC 299 ms
89,336 KB
testcase_54 AC 194 ms
94,024 KB
testcase_55 AC 463 ms
94,256 KB
testcase_56 AC 123 ms
79,248 KB
testcase_57 AC 452 ms
103,528 KB
testcase_58 AC 325 ms
89,160 KB
testcase_59 AC 213 ms
89,880 KB
testcase_60 AC 146 ms
86,412 KB
testcase_61 AC 260 ms
89,908 KB
testcase_62 AC 389 ms
96,296 KB
testcase_63 AC 306 ms
97,008 KB
testcase_64 RE -
testcase_65 AC 214 ms
81,840 KB
testcase_66 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heapify, heappop, heappush
from collections import deque


def main():
    N,S,T,K = map(int,input().split()); INF = float("inf")
    S-=1;T-=1 #0-index
    X = list(map(int,input().split()))
    G = [[] for _ in range(N)]
    M = int(input())
    for _ in range(M):
        A,B,Y = map(int,input().split())
        A-=1;B-=1
        G[A].append((Y,B))

    Q = deque([])
    Q.append(S)
    d_bfs = [INF]*N
    d_bfs[S] = 1
    while Q:
        v = Q.popleft()
        for cost, u in G[v]:
            if d_bfs[u] != INF: continue
            d_bfs[u] = d_bfs[v] + 1
            Q.append(u)
    if d_bfs[T] == INF:
        print("Impossible");exit()

    

    def dijkstra_heap2(s,G,t,K):
        INF = float("inf")
        #S:start, V: node, E: Edge, G: Graph
        V = len(G)
        #dp[i][j]: i番目の歌を歌って今j曲目(i番目の歌を含む)
        if K <= 10:
            MAX = 10
        elif K <= 130:
            MAX = 1000
        else:
            MAX = pow(10,5)
        dp = [[INF]*MAX for _ in range(V)]
        #d = [INF for _ in range(V)]
        dp[s][1] = X[s]
        prev = [[-1]*MAX for _ in range(V)]
        PQ = []
        heappush(PQ,(X[s],s,1)) #時間, 位置, 何曲目

        while PQ:
            c,v,n = heappop(PQ)
            if v == t and n >= K:
                break
            if dp[v][n] < c:
                continue
            dp[v][n] = c
            #if n+1 >= MAX: #これ以上は配列外参照
            #    continue
            for cost,u in G[v]:
                nxt = min(n+1, K)
                if dp[u][nxt] <= cost + X[u] + dp[v][n]:
                    continue
                dp[u][nxt] = cost + X[u] + dp[v][n]
                prev[u][nxt] = v
                heappush(PQ,(dp[u][n+1], u, nxt))

        return dp, prev

    d, keiro = dijkstra_heap2(S,G,T,K)
    #print(d)
    #print(keiro)
    ans = INF
    num = INF #何曲か
    for i in range(K,len(d[T])):
        if d[T][i] < ans:
            ans = d[T][i]
            num = i
    if ans == INF:
        print("Impossible")
    else:
        print("Possible")
        print(ans)
        print(num)
        ret = [T+1] #1-index
        #num -= 1
        now = T
        while num > 1:
            pre = keiro[now][num]
            ret.append(pre+1) #1-index
            now = pre
            num -= 1
        ret.reverse()
        print(*ret)



if __name__ == '__main__':
    main()
0