結果

問題 No.2674 k-Walk on Bipartite
ユーザー lam6er
提出日時 2025-04-16 15:53:09
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,193 bytes
コンパイル時間 234 ms
コンパイル使用メモリ 81,632 KB
実行使用メモリ 98,964 KB
最終ジャッジ日時 2025-04-16 15:54:04
合計ジャッジ時間 5,046 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque

def main():
    n, m = map(int, sys.stdin.readline().split())
    s, t, k = map(int, sys.stdin.readline().split())
    adj = [[] for _ in range(n + 1)]
    for _ in range(m):
        a, b = map(int, sys.stdin.readline().split())
        adj[a].append(b)
        adj[b].append(a)
    
    color = [-1] * (n + 1)
    distance = [-1] * (n + 1)
    q = deque([s])
    color[s] = 0
    distance[s] = 0
    
    while q:
        u = q.popleft()
        for v in adj[u]:
            if color[v] == -1:
                color[v] = 1 - color[u]
                distance[v] = distance[u] + 1
                q.append(v)
    
    # Check bipartite parity condition
    s_color = color[s]
    t_color = color[t]
    valid_parity = True
    if (s_color == t_color and k % 2 != 0) or (s_color != t_color and k % 2 != 1):
        valid_parity = False
    
    if not valid_parity:
        print("No")
        return
    
    # Check connectivity
    if distance[t] == -1:
        print("Unknown")
        return
    
    l = distance[t]
    if k >= l and (k - l) % 2 == 0:
        print("Yes")
    else:
        print("Unknown")

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