結果

問題 No.1190 Points
ユーザー 👑 Kazun
提出日時 2021-02-10 03:06:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 503 ms / 2,000 ms
コード長 1,027 bytes
コンパイル時間 477 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 118,104 KB
最終ジャッジ日時 2024-07-07 11:59:36
合計ジャッジ時間 10,838 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
inf=float("inf")
def bfs(v,k):
    T0=[inf]*(N+1)
    T1=[inf]*(N+1)

    if k==0:
        T0[v]=0
    else:
        T1[v]=0

    Q=deque([(v,k)])

    while Q:
        v,k=Q.popleft()

        if k==0:
            for w in E[v]:
                if T1[w]==inf:
                    T1[w]=T0[v]+1
                    Q.append((w,1))
        else:
            for w in E[v]:
                if T0[w]==inf:
                    T0[w]=T1[v]+1
                    Q.append((w,0))
    return T0,T1

#================================================
import sys
input=sys.stdin.readline
write=sys.stdout.write

N,M,P=map(int,input().split())
S,G=map(int,input().split())
E=[set() for _ in range(N+1)]
for _ in range(M):
    u,v=map(int,input().split())
    E[u].add(v)
    E[v].add(u)

p=P%2
A0,A1=bfs(S,p)
B0,B1=bfs(G,0)

X=[]
X_append=X.append
for i in range(1,N+1):
    if A0[i]+B0[i]<=P or A1[i]+B1[i]<=P:
        X_append(i)

if X:
    print(len(X))
    write("\n".join(map(str,X)))
else:
    print(-1)
0