結果

問題 No.1190 Points
ユーザー Chihaya_chanChihaya_chan
提出日時 2020-09-03 00:10:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 769 ms / 2,000 ms
コード長 1,359 bytes
コンパイル時間 320 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 111,280 KB
最終ジャッジ日時 2024-05-01 20:24:25
合計ジャッジ時間 13,132 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
67,712 KB
testcase_01 AC 51 ms
67,840 KB
testcase_02 AC 50 ms
67,968 KB
testcase_03 AC 423 ms
100,800 KB
testcase_04 AC 383 ms
98,944 KB
testcase_05 AC 358 ms
97,868 KB
testcase_06 AC 478 ms
103,344 KB
testcase_07 AC 509 ms
104,472 KB
testcase_08 AC 550 ms
104,420 KB
testcase_09 AC 599 ms
108,228 KB
testcase_10 AC 563 ms
104,948 KB
testcase_11 AC 493 ms
103,808 KB
testcase_12 AC 566 ms
106,192 KB
testcase_13 AC 470 ms
101,760 KB
testcase_14 AC 142 ms
93,312 KB
testcase_15 AC 683 ms
110,080 KB
testcase_16 AC 203 ms
91,200 KB
testcase_17 AC 645 ms
108,048 KB
testcase_18 AC 341 ms
98,688 KB
testcase_19 AC 135 ms
92,160 KB
testcase_20 AC 431 ms
101,252 KB
testcase_21 AC 251 ms
94,348 KB
testcase_22 AC 174 ms
97,024 KB
testcase_23 AC 769 ms
111,280 KB
testcase_24 AC 721 ms
110,756 KB
testcase_25 AC 468 ms
106,592 KB
testcase_26 AC 227 ms
101,632 KB
testcase_27 AC 480 ms
106,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# Points
# 拡張ダイクストラ
import heapq
N, M, P = map(int, input().split())
start, goal = map(int, input().split())
G = [[] for i in range(2*10**5+1)]
for i in range(M):
    u, v = map(int, input().split())
    G[u].append(v+10**5)
    G[v].append(u+10**5)
    G[u+10**5].append(v)
    G[v+10**5].append(u)

que = []
heapq.heapify(que)

d_s = [10**10 for i in range(2*10**5+1)]
d_s[start] = 0
heapq.heappush(que, (0, start))
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 = [10**10 for i in range(2*10**5+1)]
d_g[goal] = 0
heapq.heappush(que, (0, goal))
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):
    flag = False
    for i in range(2):
        for j in range(2):
            v = d_s[node + i*10**5] + d_g[node+j*10**5]
            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)
0