結果

問題 No.1190 Points
ユーザー LyricalMaestroLyricalMaestro
提出日時 2024-02-18 20:20:10
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,589 bytes
コンパイル時間 522 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 848,812 KB
最終ジャッジ日時 2024-02-18 20:20:15
合計ジャッジ時間 5,008 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
55,604 KB
testcase_01 AC 35 ms
55,604 KB
testcase_02 AC 35 ms
55,604 KB
testcase_03 MLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

## https://yukicoder.me/problems/no/1190

from collections import deque

def calc_dist_array(N, next_nodes, start):
    dist = [[-1] * N for _ in range(N)]
    dist[0][start] = 0
    queue = deque([(start, 0)])
    while len(queue) > 0:
        v, c = queue.popleft()
        for nv in next_nodes[v]:
            if dist[1 - c][nv] == -1:
                dist[1 - c][nv] = dist[c][v] + 1
                queue.append((nv, 1 - c))
    return dist


def main():
    N, M, P = map(int, input().split())
    S, G = map(int, input().split())
    S -= 1
    G -= 1
    next_nodes = [[] for _ in range(N)]
    for _ in range(M):
        u, v = map(int, input().split())
        u -= 1
        v -= 1
        next_nodes[u].append(v)
        next_nodes[v].append(u)

    dist_array_s = calc_dist_array(N, next_nodes, S)
    dist_array_g = calc_dist_array(N, next_nodes, G)

    p = P % 2
    answer_set = set()
    for i in range(N):
        for js in range(2):
            if dist_array_s[js][i] == -1:
                continue
            if dist_array_g[(js + p) % 2][i] == -1:
                continue
            if dist_array_s[js][i] + dist_array_g[(js + p) % 2][i] > P:
                continue
            d = dist_array_s[js][i] + dist_array_g[(js + p) % 2][i]
            if (P - d) % 2 == 0:
                answer_set.add(i + 1)
    answer_list = list(answer_set)
    answer_list.sort()

    if len(answer_list) == 0:
        print(-1)
    else:
        print(len(answer_list))
        for a in answer_list:
            print(a)



            



if __name__ == "__main__":
    main()
0