結果

問題 No.1545 [Cherry 2nd Tune N] Anthem
ユーザー taiga0629kyoprotaiga0629kyopro
提出日時 2021-06-11 22:07:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,030 ms / 3,000 ms
コード長 1,543 bytes
コンパイル時間 298 ms
コンパイル使用メモリ 82,620 KB
実行使用メモリ 373,748 KB
最終ジャッジ日時 2024-05-08 17:54:52
合計ジャッジ時間 35,440 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
53,120 KB
testcase_01 AC 46 ms
52,736 KB
testcase_02 AC 42 ms
52,992 KB
testcase_03 AC 41 ms
52,608 KB
testcase_04 AC 488 ms
173,152 KB
testcase_05 AC 2,030 ms
329,304 KB
testcase_06 AC 674 ms
166,436 KB
testcase_07 AC 558 ms
157,604 KB
testcase_08 AC 1,690 ms
256,420 KB
testcase_09 AC 539 ms
126,864 KB
testcase_10 AC 250 ms
110,224 KB
testcase_11 AC 869 ms
203,368 KB
testcase_12 AC 1,582 ms
285,352 KB
testcase_13 AC 411 ms
130,176 KB
testcase_14 AC 550 ms
184,320 KB
testcase_15 AC 194 ms
89,732 KB
testcase_16 AC 707 ms
229,000 KB
testcase_17 AC 227 ms
85,760 KB
testcase_18 AC 653 ms
132,468 KB
testcase_19 AC 687 ms
166,032 KB
testcase_20 AC 454 ms
131,836 KB
testcase_21 AC 800 ms
257,640 KB
testcase_22 AC 491 ms
169,820 KB
testcase_23 AC 577 ms
120,288 KB
testcase_24 AC 153 ms
86,144 KB
testcase_25 AC 186 ms
95,812 KB
testcase_26 AC 71 ms
69,760 KB
testcase_27 AC 148 ms
84,736 KB
testcase_28 AC 214 ms
104,664 KB
testcase_29 AC 192 ms
95,232 KB
testcase_30 AC 164 ms
91,748 KB
testcase_31 AC 186 ms
92,884 KB
testcase_32 AC 161 ms
84,864 KB
testcase_33 AC 207 ms
101,136 KB
testcase_34 AC 197 ms
96,384 KB
testcase_35 AC 364 ms
167,296 KB
testcase_36 AC 324 ms
149,420 KB
testcase_37 AC 119 ms
79,360 KB
testcase_38 AC 207 ms
105,344 KB
testcase_39 AC 140 ms
81,944 KB
testcase_40 AC 153 ms
85,888 KB
testcase_41 AC 118 ms
79,616 KB
testcase_42 AC 179 ms
92,120 KB
testcase_43 AC 189 ms
96,160 KB
testcase_44 AC 80 ms
82,432 KB
testcase_45 AC 56 ms
73,600 KB
testcase_46 AC 182 ms
96,220 KB
testcase_47 AC 213 ms
114,428 KB
testcase_48 AC 311 ms
149,752 KB
testcase_49 AC 377 ms
147,188 KB
testcase_50 AC 539 ms
191,264 KB
testcase_51 AC 129 ms
81,744 KB
testcase_52 AC 726 ms
254,524 KB
testcase_53 AC 287 ms
135,828 KB
testcase_54 AC 135 ms
86,400 KB
testcase_55 AC 546 ms
203,644 KB
testcase_56 AC 83 ms
83,456 KB
testcase_57 AC 433 ms
166,256 KB
testcase_58 AC 332 ms
149,544 KB
testcase_59 AC 146 ms
87,588 KB
testcase_60 AC 113 ms
88,960 KB
testcase_61 AC 221 ms
104,968 KB
testcase_62 AC 405 ms
160,864 KB
testcase_63 AC 247 ms
112,976 KB
testcase_64 AC 1,660 ms
368,648 KB
testcase_65 AC 175 ms
85,684 KB
testcase_66 AC 986 ms
373,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,s,t,k=map(int,input().split())
x=[0]+list(map(int,input().split()))
root=[[] for _ in range((n+3)*(k+3))]
rev=[[] for _ in range((n+3)*(k+3))]
start=x[s]
def f(i,j):
    return i*(k+1)+j

m=int(input())
for i in range(m):
    a,b,y=map(int,input().split())
    for j in range(1,k):
        root[f(a,j)].append((f(b,j+1),y+x[b]))
        rev[f(b,j+1)].append((f(a,j),y+x[b]))
    root[f(a,k)].append((f(b,k),y+x[b]))
    rev[f(b, k)].append((f(a, k), y + x[b]))


def dijkstra(N, G, s, INF=10 ** 18):
    """
    https://tjkendev.github.io/procon-library/python/graph/dijkstra.html
    O((|E|+|V|)log|V|)
    V: 頂点数
    G[v] = [(nod, cost)]:
        頂点vから遷移可能な頂点(nod)とそのコスト(cost)
    s: 始点の頂点"""
    from heapq import heappush, heappop
    N+=1
    dist = [INF] * N
    hp = [(start, s)]  # (c, v)
    dist[s] = start
    while hp:
        c, v = heappop(hp)  #vまで行くコストがc
        if dist[v] < c:
            continue
        for u, cost in G[v]:
            if dist[v] + cost < dist[u]:
                dist[u] = dist[v] + cost
                heappush(hp, (dist[u], u))
    return dist

dist=dijkstra((n+2)*(k+2),root,f(s,1))
if dist[f(t,k)]==10**18:
    print("Impossible")
    exit()

print("Possible")
print(dist[f(t,k)])
ans=[]
now=f(t,k)
while True:

    nod=now//(k+1)
    ans.append(nod)
    if now==f(s,1):break
    for node,cost in rev[now]:
        if dist[node]+cost==dist[now]:
            now=node
            break

ans=ans[::-1]
print(len(ans))
print(*ans)



0