結果

問題 No.1190 Points
ユーザー tamatotamato
提出日時 2020-08-24 20:39:57
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,015 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 128,444 KB
最終ジャッジ日時 2024-04-24 03:46:59
合計ジャッジ時間 9,610 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
54,144 KB
testcase_01 AC 47 ms
53,888 KB
testcase_02 AC 46 ms
54,272 KB
testcase_03 AC 306 ms
103,524 KB
testcase_04 AC 304 ms
100,992 KB
testcase_05 AC 277 ms
99,232 KB
testcase_06 AC 418 ms
113,496 KB
testcase_07 AC 406 ms
114,720 KB
testcase_08 AC 348 ms
124,072 KB
testcase_09 WA -
testcase_10 AC 358 ms
128,444 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    from collections import deque
    input = sys.stdin.buffer.readline

    N, M, P = map(int, input().split())
    S, G = map(int, input().split())
    adj = [[] for _ in range(N+1)]
    for _ in range(M):
        a, b = map(int, input().split())
        adj[a].append(b)
        adj[b].append(a)

    def dist(v0):
        que = deque()
        que.append(v0)
        seen = [-1] * (N+1)
        seen[v0] = 0
        par = [0] * (N+1)
        child = [[] for _ in range(N+1)]
        seq = []
        V = set()
        while que:
            v = que.popleft()
            seq.append(v)
            for u in adj[v]:
                if seen[u] == -1:
                    seen[u] = seen[v] + 1
                    par[u] = v
                    child[v].append(u)
                    que.append(u)
                elif seen[u] == seen[v]:
                    V.add(u)
                    V.add(v)
        seq.reverse()
        add = [0] * (N+1)
        for v in V:
            add[v] = 1
            que.append(v)
            while que:
                vv = que.pop()
                for u in child[vv]:
                    que.append(u)
                    add[u] = 1
        for v in seq:
            if add[v] == 0:
                val = 10**10
                for u in child[v]:
                    val = min(val, add[u] + 2)
                add[v] = val
        seq.reverse()
        for v in seq:
            for u in child[v]:
                add[u] = min(add[u], add[v])
        return seen, add

    ds, adds = dist(S)
    dg, addg = dist(G)
    ans = []
    for v in range(1, N+1):
        if ds[v] + dg[v] <= P:
            if (ds[v] + dg[v])%2 == P%2:
                ans.append(v)
            else:
                if ds[v] + dg[v] + min(adds[v], addg[v]) <= P:
                    ans.append(v)
    if ans:
        print(len(ans))
        for a in ans:
            print(a)
    else:
        print(-1)


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