結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,152 KB
testcase_01 AC 74 ms
71,208 KB
testcase_02 AC 75 ms
71,412 KB
testcase_03 AC 79 ms
71,248 KB
testcase_04 AC 212 ms
92,652 KB
testcase_05 AC 2,626 ms
158,480 KB
testcase_06 WA -
testcase_07 AC 241 ms
100,024 KB
testcase_08 AC 2,523 ms
127,804 KB
testcase_09 AC 1,096 ms
103,296 KB
testcase_10 AC 233 ms
107,080 KB
testcase_11 AC 622 ms
112,900 KB
testcase_12 AC 1,128 ms
132,636 KB
testcase_13 AC 332 ms
99,320 KB
testcase_14 AC 194 ms
96,804 KB
testcase_15 WA -
testcase_16 AC 227 ms
105,416 KB
testcase_17 AC 563 ms
90,868 KB
testcase_18 AC 474 ms
134,560 KB
testcase_19 AC 1,062 ms
116,776 KB
testcase_20 AC 612 ms
89,540 KB
testcase_21 AC 262 ms
108,216 KB
testcase_22 AC 290 ms
122,284 KB
testcase_23 AC 2,767 ms
130,756 KB
testcase_24 AC 1,070 ms
90,368 KB
testcase_25 AC 358 ms
80,628 KB
testcase_26 AC 194 ms
79,276 KB
testcase_27 AC 328 ms
80,492 KB
testcase_28 AC 608 ms
84,340 KB
testcase_29 AC 934 ms
89,984 KB
testcase_30 AC 515 ms
81,772 KB
testcase_31 AC 565 ms
84,996 KB
testcase_32 AC 234 ms
79,124 KB
testcase_33 AC 768 ms
86,128 KB
testcase_34 AC 544 ms
83,892 KB
testcase_35 AC 1,007 ms
89,028 KB
testcase_36 AC 849 ms
85,780 KB
testcase_37 AC 269 ms
79,532 KB
testcase_38 AC 451 ms
81,768 KB
testcase_39 AC 250 ms
79,656 KB
testcase_40 AC 472 ms
82,144 KB
testcase_41 AC 224 ms
79,112 KB
testcase_42 AC 693 ms
88,932 KB
testcase_43 AC 709 ms
86,900 KB
testcase_44 AC 109 ms
80,796 KB
testcase_45 AC 89 ms
90,092 KB
testcase_46 AC 809 ms
94,024 KB
testcase_47 AC 614 ms
93,720 KB
testcase_48 AC 493 ms
101,268 KB
testcase_49 AC 1,022 ms
98,568 KB
testcase_50 AC 1,239 ms
106,048 KB
testcase_51 AC 1,728 ms
109,788 KB
testcase_52 AC 1,281 ms
106,896 KB
testcase_53 AC 620 ms
95,268 KB
testcase_54 AC 891 ms
103,456 KB
testcase_55 AC 1,104 ms
102,400 KB
testcase_56 AC 107 ms
81,032 KB
testcase_57 AC 1,630 ms
111,248 KB
testcase_58 AC 706 ms
94,640 KB
testcase_59 AC 798 ms
97,192 KB
testcase_60 AC 150 ms
88,092 KB
testcase_61 AC 1,197 ms
97,360 KB
testcase_62 AC 1,400 ms
104,644 KB
testcase_63 AC 1,417 ms
104,352 KB
testcase_64 AC 2,519 ms
199,812 KB
testcase_65 AC 508 ms
90,472 KB
testcase_66 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heapify, heappop, heappush
from math import inf

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))

    
    

    def dijkstra_heap2(s,G,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 = 15
        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 dp[v][n] < c:
                continue
            dp[v][n] = c
            if n+1 >= MAX: #これ以上は配列外参照
                continue
            for cost,u in G[v]:
                if dp[u][n+1] <= cost + X[u] + dp[v][n]:
                    continue
                dp[u][n+1] = cost + X[u] + dp[v][n]
                prev[u][n+1] = v
                heappush(PQ,(dp[u][n+1], u, n+1))

        return dp, prev

    d, keiro = dijkstra_heap2(S,G,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