結果

問題 No.3291 K-step Navigation
ユーザー titia
提出日時 2025-10-09 01:51:33
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 901 bytes
コンパイル時間 408 ms
コンパイル使用メモリ 12,288 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2025-10-09 01:51:38
合計ジャッジ時間 3,878 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 44 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N,M,K,s,t=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)

if K==1:
    print("Yes")
    exit()

if E[s]==[] and E[t]==[]:
    print("No")
    exit()

if len(E[s])==1 and len(E[t])==1 and E[s][0]==t:
    flag=0
    USE=[-1]*(N+1)

    for i in range(1,N+1):
        if USE[i]!=-1:
            continue
        Q=[i]
        USE[i]=0

        while Q and flag==0:
            x=Q.pop()
            for to in E[x]:
                if USE[to]==USE[x]:
                    flag=1
                    break
                if USE[to]==-1:
                    USE[to]=USE[x]^1
                    Q.append(to)

    if flag:
        print("Yes")
        exit()
                    
    if K%2==1:
        print("Yes")
    else:
        print("No")
    exit()

print("Yes")
0