結果

問題 No.2674 k-Walk on Bipartite
コンテスト
ユーザー LyricalMaestro
提出日時 2026-09-07 02:01:45
言語 PyPy3
(7.3.23 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 1,202 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 377 ms
コンパイル使用メモリ 83,104 KB
実行使用メモリ 107,412 KB
最終ジャッジ日時 2026-09-07 02:01:59
合計ジャッジ時間 6,250 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

## https://yukicoder.me/problems/no/2674

from collections import deque

MAX_INT = 10 ** 18

def main():
    N, M= map(int ,input().split())
    s, t, k = map(int, input().split())
    s -= 1
    t -= 1
    next_nodes = [[] for _ in range(N)]
    for _ in range(M):
        a, b = map(int, input().split())
        next_nodes[a - 1].append(b - 1)
        next_nodes[b - 1].append(a - 1)

    passed = [-1] * N
    dists = [MAX_INT] * N
    queue = deque()
    queue.append(s)
    passed[s] = 0
    dists[s] = 0
    while len(queue) > 0:
        v = queue.popleft()
        for w in next_nodes[v]:
            if passed[w] == -1:
                passed[w] = 1 - passed[v]
                dists[w] = 1 + dists[v]
                queue.append(w)

    if passed[t] == -1:
        print("Unknown")
        return

    if passed[t] == 0:
        if k % 2 == 1:
            print("No")
        elif dists[t] <= k:
            print("Yes")
        else:
            print("Unknown")
    elif passed[t] == 1:
        if k % 2 == 0:
            print("No")
        elif dists[t] <= k:
            print("Yes")
        else:
            print("Unknown")


            







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