結果
| 問題 |
No.2674 k-Walk on Bipartite
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-16 16:04:08 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,676 bytes |
| コンパイル時間 | 511 ms |
| コンパイル使用メモリ | 81,804 KB |
| 実行使用メモリ | 98,944 KB |
| 最終ジャッジ日時 | 2025-04-16 16:10:29 |
| 合計ジャッジ時間 | 5,761 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 WA * 10 |
ソースコード
import sys
from collections import deque
def main():
sys.setrecursionlimit(1 << 25)
N, M = map(int, sys.stdin.readline().split())
s, t, k = map(int, sys.stdin.readline().split())
edges = [[] for _ in range(N+1)] # 1-based indexing
for _ in range(M):
a, b = map(int, sys.stdin.readline().split())
edges[a].append(b)
edges[b].append(a)
# Bipartite coloring
color = [-1] * (N+1)
for start in range(1, N+1):
if color[start] == -1:
color[start] = 0
q = deque([start])
while q:
u = q.popleft()
for v in edges[u]:
if color[v] == -1:
color[v] = color[u] ^ 1
q.append(v)
# Check parity of k against color difference
if (color[s] == color[t]) != (k % 2 == 0):
print("No")
return
# BFS to find shortest path in F
visited = [-1] * (N+1)
q = deque([s])
visited[s] = 0
found = False
while q:
u = q.popleft()
if u == t:
found = True
break
for v in edges[u]:
if visited[v] == -1:
visited[v] = visited[u] + 1
q.append(v)
if found:
l = visited[t]
if k >= l and (k - l) % 2 == 0 and (M >= 1 or k == l):
print("Yes")
else:
print("Unknown")
else:
if color[s] == color[t]:
print("No")
else:
if k >= 1 and (k - 1) % 2 == 0:
print("Unknown")
else:
print("No")
if __name__ == "__main__":
main()
lam6er