結果
問題 |
No.2674 k-Walk on Bipartite
|
ユーザー |
![]() |
提出日時 | 2025-06-12 16:24:52 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,611 bytes |
コンパイル時間 | 261 ms |
コンパイル使用メモリ | 82,580 KB |
実行使用メモリ | 125,152 KB |
最終ジャッジ日時 | 2025-06-12 16:24:58 |
合計ジャッジ時間 | 5,175 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 WA * 6 |
ソースコード
import sys from collections import deque def main(): input = sys.stdin.read().split() ptr = 0 N = int(input[ptr]) ptr += 1 M = int(input[ptr]) ptr += 1 s = int(input[ptr]) - 1 # converting to 0-based ptr += 1 t = int(input[ptr]) - 1 ptr += 1 k = int(input[ptr]) ptr += 1 adj = [[] for _ in range(N)] for _ in range(M): a = int(input[ptr]) - 1 ptr += 1 b = int(input[ptr]) - 1 ptr += 1 adj[a].append(b) adj[b].append(a) # BFS to compute distance and bipartition visited = [False] * N color = [-1] * N distance = [-1] * N q = deque() q.append(s) visited[s] = True color[s] = 0 distance[s] = 0 while q: u = q.popleft() for v in adj[u]: if not visited[v]: visited[v] = True color[v] = 1 - color[u] distance[v] = distance[u] + 1 q.append(v) else: # Check bipartition consistency (though problem states F is bipartite) if color[v] == color[u]: print("No") return if not visited[t]: # s and t are in different components print("Unknown") return # Check parity required_parity = distance[t] % 2 if k % 2 != required_parity: print("No") return # Check if k >= d and (k - d) is even d = distance[t] if k >= d and (k - d) % 2 == 0: print("Yes") else: print("Unknown") if __name__ == "__main__": main()