結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,436 KB
testcase_01 AC 74 ms
71,524 KB
testcase_02 AC 76 ms
71,184 KB
testcase_03 AC 78 ms
71,572 KB
testcase_04 AC 184 ms
92,308 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 210 ms
99,352 KB
testcase_08 AC 992 ms
109,968 KB
testcase_09 AC 626 ms
96,596 KB
testcase_10 AC 211 ms
106,180 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 382 ms
87,564 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 458 ms
86,764 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 1,000 ms
110,416 KB
testcase_24 AC 1,036 ms
90,428 KB
testcase_25 AC 348 ms
80,904 KB
testcase_26 AC 189 ms
79,036 KB
testcase_27 AC 314 ms
80,848 KB
testcase_28 AC 583 ms
84,600 KB
testcase_29 AC 915 ms
90,368 KB
testcase_30 AC 507 ms
81,932 KB
testcase_31 AC 549 ms
85,092 KB
testcase_32 AC 226 ms
79,060 KB
testcase_33 AC 751 ms
86,404 KB
testcase_34 AC 526 ms
83,932 KB
testcase_35 AC 968 ms
89,148 KB
testcase_36 AC 832 ms
86,152 KB
testcase_37 AC 260 ms
79,852 KB
testcase_38 AC 442 ms
82,084 KB
testcase_39 AC 243 ms
79,604 KB
testcase_40 AC 446 ms
82,568 KB
testcase_41 AC 210 ms
79,232 KB
testcase_42 AC 662 ms
89,064 KB
testcase_43 AC 674 ms
86,896 KB
testcase_44 AC 105 ms
80,860 KB
testcase_45 AC 86 ms
90,400 KB
testcase_46 AC 734 ms
93,908 KB
testcase_47 AC 553 ms
93,800 KB
testcase_48 AC 456 ms
101,652 KB
testcase_49 AC 927 ms
98,628 KB
testcase_50 AC 1,134 ms
106,128 KB
testcase_51 AC 1,616 ms
109,928 KB
testcase_52 AC 1,190 ms
106,792 KB
testcase_53 AC 562 ms
95,368 KB
testcase_54 AC 813 ms
103,604 KB
testcase_55 AC 1,026 ms
102,808 KB
testcase_56 AC 104 ms
81,180 KB
testcase_57 AC 1,524 ms
111,496 KB
testcase_58 AC 641 ms
94,772 KB
testcase_59 AC 734 ms
97,228 KB
testcase_60 AC 147 ms
88,180 KB
testcase_61 AC 1,106 ms
97,792 KB
testcase_62 AC 1,352 ms
104,812 KB
testcase_63 AC 1,328 ms
104,484 KB
testcase_64 WA -
testcase_65 AC 440 ms
90,832 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 = 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 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