結果

問題 No.1190 Points
ユーザー titia
提出日時 2020-08-22 15:56:02
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 996 ms / 2,000 ms
コード長 1,211 bytes
コンパイル時間 206 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 47,104 KB
最終ジャッジ日時 2024-10-15 10:05:26
合計ジャッジ時間 16,551 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import deque

N,M,P=map(int,input().split())
S,G=map(int,input().split())
E=[[] for i in range(N+1)]

for i in range(M):
    x,y=map(int,input().split())
    E[x].append(y)
    E[y].append(x)

SE=[1<<50]*(N+1)
SO=[1<<50]*(N+1)
GE=[1<<50]*(N+1)
GO=[1<<50]*(N+1)

SE[S]=0
GE[G]=0

Q=deque([S])

while Q:
    x=Q.popleft()
    for to in E[x]:
        if SE[x]<1<<50 and SO[to]>SE[x]+1:
            SO[to]=SE[x]+1
            Q.append(to)
        if SO[x]<1<<50 and SE[to]>SO[x]+1:
            SE[to]=SO[x]+1
            Q.append(to)

Q=deque([G])

while Q:
    x=Q.popleft()
    for to in E[x]:
        if GE[x]<1<<50 and GO[to]>GE[x]+1:
            GO[to]=GE[x]+1
            Q.append(to)
        if GO[x]<1<<50 and GE[to]>GO[x]+1:
            GE[to]=GO[x]+1
            Q.append(to)

ANS=[]
for i in range(1,N+1):
    if P%2==0:
        if SE[i]+GE[i]<=P:
            ANS.append(i)
        elif SO[i]+GO[i]<=P:
            ANS.append(i)
    else:
        if SE[i]+GO[i]<=P:
            ANS.append(i)
        elif SO[i]+GE[i]<=P:
            ANS.append(i)

ANS.sort()
if len(ANS)==0:
    print(-1)
else:
    print(len(ANS))
    print("\n".join(map(str,ANS)))
0