結果

問題 No.3291 K-step Navigation
ユーザー ゼット
提出日時 2025-10-03 23:19:15
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 872 bytes
コンパイル時間 504 ms
コンパイル使用メモリ 82,828 KB
実行使用メモリ 78,044 KB
最終ジャッジ日時 2025-10-03 23:19:33
合計ジャッジ時間 10,587 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 47 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M,K,X,Y=map(int,input().split())
G=[[] for i in range(N)]
for i in range(M):
  a,b=map(int,input().split())
  G[a-1].append(b-1)
  G[b-1].append(a-1)
ans=False
h=[10**20]*N
from collections import deque
for i in range(N):
  dist=[-1]*N
  if dist[i]==-1:
    dist[i]=0
    S=deque()
    S.append(i)
    while S:
      x=S.popleft()
      for y in G[x]:
        if dist[y]==-1:
          dist[y]=dist[x]+1
          S.append(y)
        else:
          if dist[y]%2!=(dist[x]+1)%2:
            h[y]=min(h[y],dist[x]+1)
if len(G[X-1])==1 and G[X-1][0]==Y-1:
  if K%2==1:
    print('Yes')
    exit()
  if len(G[Y-1])>1:
    print('Yes')
    exit()
  d=min(h)
  if d<=K-2:
    print('Yes')
    exit()
  if ans==True:
    print('Yes')
  else:
    print('No')
  exit()
if len(G[X-1])+len(G[Y-1])>0:
  print('Yes')
else:
  if K%2==1:
    print('Yes')
  else:
    print('No')
    
0