結果
| 問題 |
No.1190 Points
|
| コンテスト | |
| ユーザー |
Chihaya_chan
|
| 提出日時 | 2020-09-03 00:01:19 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,439 bytes |
| コンパイル時間 | 358 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 193,748 KB |
| 最終ジャッジ日時 | 2024-11-22 02:31:44 |
| 合計ジャッジ時間 | 37,578 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 TLE * 4 |
ソースコード
# Points
# 拡張ダイクストラ
import heapq
N, M, P = map(int, input().split())
start, goal = map(int, input().split())
G = {(i, j): [] for i in range(1, N+1) for j in range(2)}
for i in range(M):
u, v = map(int, input().split())
G[(u, 0)].append((v, 1))
G[(v, 0)].append((u, 1))
G[(u, 1)].append((v, 0))
G[(v, 1)].append((u, 0))
que = []
heapq.heapify(que)
d_s = {(i, j): 10**10 for i in range(1, N+1) for j in range(2)}
d_s[(start, 0)] = 0
heapq.heappush(que, (0, (start, 0)))
while que:
cost, v = heapq.heappop(que)
if d_s[v] < cost:
continue
for e in G[v]:
if d_s[e] > d_s[v] + 1:
d_s[e] = d_s[v] + 1
heapq.heappush(que, (d_s[e], e))
d_g = {(i, j): 10**10 for i in range(1, N+1) for j in range(2)}
d_g[(goal, 0)] = 0
heapq.heappush(que, (0, (goal, 0)))
while que:
cost, v = heapq.heappop(que)
if d_g[v] < cost:
continue
for e in G[v]:
if d_g[e] > d_g[v] + 1:
d_g[e] = d_g[v] + 1
heapq.heappush(que, (d_g[e], e))
is_accessible = [0 for i in range(N+1)]
for node in range(1, N+1):
for i in range(2):
for j in range(2):
v = d_s[(node, i)] + d_g[(node, j)]
if v <= P and v % 2 == P % 2:
is_accessible[node] = 1
K = sum(is_accessible)
if K == 0:
print(-1)
exit()
print(K)
for i in range(1, N+1):
if is_accessible[i] == 1:
print(i)
Chihaya_chan