結果

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

ソースコード

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:
        if N == 2:
            print("No")
        else:
            print("Unknown")
        return

    # s とtが同じである場合
    if s == t:
        nown = 0
        for i in range(N):
            if passed[i] != -1:
                nown += 1
        if nown == 1:
            if k % 2 == 1:
                print("No")
            else:
                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