結果

問題 No.1545 [Cherry 2nd Tune N] Anthem
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-06-11 21:54:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,802 ms / 3,000 ms
コード長 2,008 bytes
コンパイル時間 396 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 429,544 KB
最終ジャッジ日時 2024-05-08 17:37:58
合計ジャッジ時間 33,918 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,992 KB
testcase_01 AC 41 ms
52,864 KB
testcase_02 AC 41 ms
52,736 KB
testcase_03 AC 40 ms
52,992 KB
testcase_04 AC 389 ms
186,440 KB
testcase_05 AC 1,802 ms
330,176 KB
testcase_06 AC 543 ms
170,752 KB
testcase_07 AC 493 ms
166,040 KB
testcase_08 AC 1,178 ms
197,788 KB
testcase_09 AC 322 ms
105,600 KB
testcase_10 AC 162 ms
102,448 KB
testcase_11 AC 725 ms
202,624 KB
testcase_12 AC 1,433 ms
281,884 KB
testcase_13 AC 352 ms
133,840 KB
testcase_14 AC 512 ms
205,696 KB
testcase_15 AC 158 ms
88,652 KB
testcase_16 AC 697 ms
259,172 KB
testcase_17 AC 174 ms
81,408 KB
testcase_18 AC 526 ms
115,404 KB
testcase_19 AC 567 ms
163,200 KB
testcase_20 AC 402 ms
107,264 KB
testcase_21 AC 1,067 ms
305,676 KB
testcase_22 AC 404 ms
179,640 KB
testcase_23 AC 407 ms
105,184 KB
testcase_24 AC 155 ms
82,176 KB
testcase_25 AC 176 ms
87,172 KB
testcase_26 AC 79 ms
71,936 KB
testcase_27 AC 174 ms
82,212 KB
testcase_28 AC 206 ms
89,856 KB
testcase_29 AC 155 ms
85,632 KB
testcase_30 AC 154 ms
85,328 KB
testcase_31 AC 180 ms
87,460 KB
testcase_32 AC 142 ms
81,024 KB
testcase_33 AC 185 ms
89,856 KB
testcase_34 AC 181 ms
86,968 KB
testcase_35 AC 302 ms
116,356 KB
testcase_36 AC 254 ms
106,368 KB
testcase_37 AC 124 ms
79,088 KB
testcase_38 AC 192 ms
91,392 KB
testcase_39 AC 144 ms
80,000 KB
testcase_40 AC 151 ms
82,304 KB
testcase_41 AC 125 ms
78,352 KB
testcase_42 AC 169 ms
85,428 KB
testcase_43 AC 183 ms
87,076 KB
testcase_44 AC 100 ms
82,176 KB
testcase_45 AC 100 ms
97,408 KB
testcase_46 AC 216 ms
94,312 KB
testcase_47 AC 263 ms
111,560 KB
testcase_48 AC 430 ms
166,324 KB
testcase_49 AC 377 ms
137,620 KB
testcase_50 AC 638 ms
187,828 KB
testcase_51 AC 147 ms
80,640 KB
testcase_52 AC 808 ms
218,316 KB
testcase_53 AC 313 ms
134,676 KB
testcase_54 AC 152 ms
84,000 KB
testcase_55 AC 564 ms
184,164 KB
testcase_56 AC 94 ms
83,328 KB
testcase_57 AC 471 ms
152,752 KB
testcase_58 AC 363 ms
139,836 KB
testcase_59 AC 173 ms
87,296 KB
testcase_60 AC 139 ms
97,536 KB
testcase_61 AC 219 ms
98,212 KB
testcase_62 AC 402 ms
141,660 KB
testcase_63 AC 300 ms
104,860 KB
testcase_64 AC 1,513 ms
320,128 KB
testcase_65 AC 179 ms
84,604 KB
testcase_66 AC 1,176 ms
429,544 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