結果
問題 |
No.2674 k-Walk on Bipartite
|
ユーザー |
![]() |
提出日時 | 2025-06-12 15:01:21 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,408 bytes |
コンパイル時間 | 138 ms |
コンパイル使用メモリ | 82,444 KB |
実行使用メモリ | 125,096 KB |
最終ジャッジ日時 | 2025-06-12 15:01:34 |
合計ジャッジ時間 | 4,897 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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]) ptr += 1 t = int(input[ptr]) ptr += 1 k = int(input[ptr]) ptr += 1 adj = [[] for _ in range(N+1)] for _ in range(M): a = int(input[ptr]) ptr += 1 b = int(input[ptr]) ptr += 1 adj[a].append(b) adj[b].append(a) color = [-1] * (N + 1) dist = [-1] * (N + 1) q = deque() q.append(s) color[s] = 0 dist[s] = 0 while q: u = q.popleft() for v in adj[u]: if color[v] == -1: color[v] = color[u] ^ 1 dist[v] = dist[u] + 1 q.append(v) else: if color[v] == color[u]: pass if color[t] == -1: print("Unknown") return if (color[s] == color[t]) and (k % 2 != 0): print("No") return if (color[s] != color[t]) and (k % 2 != 1): print("No") return if dist[t] == -1: print("Unknown") return d = dist[t] if k < d: print("Unknown") else: if (k - d) % 2 == 0: print("Yes") else: print("No") if __name__ == "__main__": main()