結果

問題 No.1545 [Cherry 2nd Tune N] Anthem
ユーザー qibqib
提出日時 2022-11-09 21:50:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,334 ms / 3,000 ms
コード長 1,276 bytes
コンパイル時間 298 ms
コンパイル使用メモリ 86,836 KB
実行使用メモリ 433,208 KB
最終ジャッジ日時 2023-09-30 08:51:30
合計ジャッジ時間 46,883 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
71,232 KB
testcase_01 AC 80 ms
71,252 KB
testcase_02 AC 80 ms
71,028 KB
testcase_03 AC 79 ms
70,940 KB
testcase_04 AC 580 ms
195,092 KB
testcase_05 AC 2,334 ms
429,900 KB
testcase_06 AC 743 ms
206,056 KB
testcase_07 AC 591 ms
175,376 KB
testcase_08 AC 1,718 ms
328,248 KB
testcase_09 AC 517 ms
147,420 KB
testcase_10 AC 244 ms
94,052 KB
testcase_11 AC 960 ms
257,088 KB
testcase_12 AC 1,853 ms
354,908 KB
testcase_13 AC 484 ms
142,456 KB
testcase_14 AC 672 ms
219,216 KB
testcase_15 AC 215 ms
90,944 KB
testcase_16 AC 997 ms
290,992 KB
testcase_17 AC 259 ms
90,920 KB
testcase_18 AC 611 ms
128,732 KB
testcase_19 AC 798 ms
202,788 KB
testcase_20 AC 504 ms
149,868 KB
testcase_21 AC 1,127 ms
325,340 KB
testcase_22 AC 544 ms
177,012 KB
testcase_23 AC 607 ms
137,916 KB
testcase_24 AC 213 ms
98,696 KB
testcase_25 AC 274 ms
107,688 KB
testcase_26 AC 107 ms
77,028 KB
testcase_27 AC 209 ms
90,876 KB
testcase_28 AC 306 ms
117,392 KB
testcase_29 AC 255 ms
110,004 KB
testcase_30 AC 241 ms
108,096 KB
testcase_31 AC 277 ms
107,544 KB
testcase_32 AC 232 ms
92,424 KB
testcase_33 AC 297 ms
117,040 KB
testcase_34 AC 288 ms
110,332 KB
testcase_35 AC 542 ms
192,616 KB
testcase_36 AC 449 ms
164,628 KB
testcase_37 AC 173 ms
83,012 KB
testcase_38 AC 308 ms
122,528 KB
testcase_39 AC 199 ms
86,748 KB
testcase_40 AC 200 ms
99,644 KB
testcase_41 AC 160 ms
80,704 KB
testcase_42 AC 260 ms
105,032 KB
testcase_43 AC 263 ms
111,728 KB
testcase_44 AC 115 ms
81,332 KB
testcase_45 AC 97 ms
79,420 KB
testcase_46 AC 254 ms
108,972 KB
testcase_47 AC 298 ms
131,248 KB
testcase_48 AC 436 ms
161,108 KB
testcase_49 AC 483 ms
169,944 KB
testcase_50 AC 704 ms
231,956 KB
testcase_51 AC 174 ms
85,200 KB
testcase_52 AC 1,109 ms
352,464 KB
testcase_53 AC 389 ms
155,352 KB
testcase_54 AC 185 ms
93,776 KB
testcase_55 AC 692 ms
258,272 KB
testcase_56 AC 117 ms
82,036 KB
testcase_57 AC 613 ms
202,724 KB
testcase_58 AC 452 ms
169,664 KB
testcase_59 AC 205 ms
94,556 KB
testcase_60 AC 175 ms
96,592 KB
testcase_61 AC 310 ms
119,336 KB
testcase_62 AC 546 ms
202,816 KB
testcase_63 AC 352 ms
129,504 KB
testcase_64 AC 1,854 ms
433,208 KB
testcase_65 AC 217 ms
92,376 KB
testcase_66 AC 1,047 ms
396,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

INF = 1 << 60

n, s, t, k = map(int, input().split())
s -= 1
t -= 1
x = list(map(int, input().split()))

m = int(input())
edges = []
idx = {}
vs = [s, (k - 1) * n + t]
idx[vs[0]] = 0
idx[vs[1]] = 1
src = 0
dst = 1
for _ in range(m):
  a, b, y = map(int, input().split())
  a -= 1
  b -= 1
  for i in range(k):
    u = i * n + a
    v = min(i + 1, k - 1) * n + b
    if idx.get(u, None) is None:
      idx[u] = len(idx)
      vs.append(u)
    if idx.get(v, None) is None:
      idx[v] = len(idx)
      vs.append(v)

    edges.append((idx[u], idx[v], y + x[b]))

g = [[] for _ in range(len(idx))]
for u, v, w in edges:
  g[u].append((v, w))

dist = [INF for _ in range(len(idx))]
dist[src] = x[s]
prev = [None for _ in range(len(idx))]
hp = [(dist[src], src)]
while len(hp) > 0:
  cd, cur = heapq.heappop(hp)
  if cd > dist[cur]:
    continue

  for nxt, cost in g[cur]:
    if dist[cur] + cost < dist[nxt]:
      dist[nxt] = dist[cur] + cost
      prev[nxt] = cur
      heapq.heappush(hp, (dist[nxt], nxt))

if dist[dst] < INF:
  print("Possible")
  print(dist[dst])

  cur = dst
  order = []
  while not cur is None:
    order.append(vs[cur] % n + 1)
    cur = prev[cur]

  order.reverse()
  print(len(order))
  print(*order, sep=" ")
else:
  print("Impossible")
0