結果

問題 No.1545 [Cherry 2nd Tune N] Anthem
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-06-11 21:54:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,881 ms / 3,000 ms
コード長 2,008 bytes
コンパイル時間 317 ms
コンパイル使用メモリ 86,928 KB
実行使用メモリ 420,064 KB
最終ジャッジ日時 2023-08-21 12:18:43
合計ジャッジ時間 40,351 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,420 KB
testcase_01 AC 76 ms
71,388 KB
testcase_02 AC 74 ms
71,156 KB
testcase_03 AC 73 ms
71,048 KB
testcase_04 AC 417 ms
186,680 KB
testcase_05 AC 1,881 ms
331,404 KB
testcase_06 AC 609 ms
170,912 KB
testcase_07 AC 529 ms
169,192 KB
testcase_08 AC 1,240 ms
200,096 KB
testcase_09 AC 370 ms
106,328 KB
testcase_10 AC 194 ms
102,516 KB
testcase_11 AC 770 ms
204,068 KB
testcase_12 AC 1,474 ms
283,480 KB
testcase_13 AC 414 ms
134,644 KB
testcase_14 AC 561 ms
206,556 KB
testcase_15 AC 200 ms
90,072 KB
testcase_16 AC 746 ms
261,104 KB
testcase_17 AC 197 ms
82,064 KB
testcase_18 AC 586 ms
116,836 KB
testcase_19 AC 627 ms
161,668 KB
testcase_20 AC 353 ms
107,784 KB
testcase_21 AC 1,064 ms
296,660 KB
testcase_22 AC 435 ms
181,428 KB
testcase_23 AC 488 ms
107,056 KB
testcase_24 AC 187 ms
83,748 KB
testcase_25 AC 207 ms
87,464 KB
testcase_26 AC 109 ms
77,900 KB
testcase_27 AC 211 ms
83,724 KB
testcase_28 AC 231 ms
90,624 KB
testcase_29 AC 182 ms
87,172 KB
testcase_30 AC 179 ms
86,348 KB
testcase_31 AC 211 ms
87,836 KB
testcase_32 AC 179 ms
82,836 KB
testcase_33 AC 213 ms
89,824 KB
testcase_34 AC 213 ms
88,004 KB
testcase_35 AC 345 ms
118,300 KB
testcase_36 AC 283 ms
106,060 KB
testcase_37 AC 152 ms
79,900 KB
testcase_38 AC 218 ms
91,312 KB
testcase_39 AC 179 ms
81,332 KB
testcase_40 AC 182 ms
83,868 KB
testcase_41 AC 153 ms
79,484 KB
testcase_42 AC 202 ms
86,488 KB
testcase_43 AC 223 ms
88,124 KB
testcase_44 AC 116 ms
82,800 KB
testcase_45 AC 119 ms
94,564 KB
testcase_46 AC 246 ms
95,028 KB
testcase_47 AC 298 ms
112,188 KB
testcase_48 AC 467 ms
170,048 KB
testcase_49 AC 417 ms
138,464 KB
testcase_50 AC 644 ms
189,104 KB
testcase_51 AC 179 ms
81,924 KB
testcase_52 AC 822 ms
219,176 KB
testcase_53 AC 369 ms
135,292 KB
testcase_54 AC 184 ms
85,524 KB
testcase_55 AC 617 ms
183,588 KB
testcase_56 AC 118 ms
83,732 KB
testcase_57 AC 522 ms
153,592 KB
testcase_58 AC 400 ms
140,496 KB
testcase_59 AC 207 ms
88,312 KB
testcase_60 AC 172 ms
97,196 KB
testcase_61 AC 247 ms
98,240 KB
testcase_62 AC 449 ms
142,364 KB
testcase_63 AC 339 ms
105,452 KB
testcase_64 AC 1,576 ms
323,060 KB
testcase_65 AC 224 ms
86,264 KB
testcase_66 AC 1,102 ms
420,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

S -> T
のパスを作る

頂点にも重みがある
結局 N*K が小さい
ので
Dijkstraで行けそう?

in,out,層
の3次元必要

各Kに関して、2N個いる。

2NK + v + (N <- outは足す)

"""

from sys import stdin

import heapq
def Dijkstra(lis,start):

    ret = [float("inf")] * len(lis)
    ret[start] = 0
    end_flag = [False] * len(lis)
    end_num = 0

    plis = [i for i in range(len(lis))]
    
    q = [(0,start)]

    while len(q) > 0:

        ncost,now = heapq.heappop(q)

        if end_flag[now]:
            continue

        end_flag[now] = True
        end_num += 1

        if end_num == len(lis):
            break

        for nex,ecost in lis[now]:

            if ret[nex] > ncost + ecost:
                ret[nex] = ncost + ecost
                heapq.heappush(q , (ret[nex] , nex))
                plis[nex] = now

    return ret,plis

#io == 0 == in
#io == 1 == out

def enc(v,k,io):
    if io == 0:
        return 2*N*k + v
    else:
        return 2*N*k + v + N

def dec(x):
    v = x % N
    io = (x//N) % 2
    k = (x//(2*N))
    return v,k,io

N,S,T,K = map(int,stdin.readline().split())
X = list(map(int,stdin.readline().split()))
S -= 1
T -= 1

st = enc(S,0,0)
go = enc(T,K-1,1)

lis = [ [] for i in range(N*(K)*2) ]
for k in range(K):
    for v in range(N):
        vs = enc(v,k,0)
        vg = enc(v,k,1)
        lis[vs].append( (vg,X[v]) )

M = int(stdin.readline())
for i in range(M):
    A,B,Y = map(int,stdin.readline().split())
    A -= 1
    B -= 1

    for k in range(K-1):
        lis[enc(A,k,1)].append( (enc(B,k+1,0),Y) )

    lis[enc(A,K-1,1)].append( (enc(B,K-1,0),Y) )

dlis,plis = Dijkstra(lis,st)
if dlis[go] == float("inf"):
    print ("Impossible")
else:
    print ("Possible")
    print (dlis[go])
    ans = [go]

    v = go
    while v != st:
        ans.append(plis[v])
        v = plis[v]

    anst = []
    for i in ans:
        anst.append(dec(i)[0] + 1)

    anst.reverse()
    print (len(anst)//2)
    print (*anst[::2])
0