結果
問題 |
No.1400 すごろくで世界旅行
|
ユーザー |
![]() |
提出日時 | 2025-04-16 00:14:37 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,533 bytes |
コンパイル時間 | 274 ms |
コンパイル使用メモリ | 81,412 KB |
実行使用メモリ | 112,348 KB |
最終ジャッジ日時 | 2025-04-16 00:15:51 |
合計ジャッジ時間 | 2,560 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 15 WA * 3 |
ソースコード
import sys from collections import deque def main(): V, D = map(int, sys.stdin.readline().split()) E = [sys.stdin.readline().strip() for _ in range(V)] # Create adjacency list adj = [[] for _ in range(V)] for i in range(V): for j in range(V): if E[i][j] == '1': adj[i].append(j) # Check if any vertex has zero degree for i in range(V): if len(adj[i]) == 0: print("No") return # Check connectivity using BFS from vertex 0 visited = [False] * V q = deque([0]) visited[0] = True count = 1 while q: u = q.popleft() for v in adj[u]: if not visited[v]: visited[v] = True count += 1 q.append(v) if count != V: print("No") return # Check bipartite using BFS color = [-1] * V color[0] = 0 q = deque([0]) is_bipartite = True while q and is_bipartite: u = q.popleft() for v in adj[u]: if color[v] == -1: color[v] = color[u] ^ 1 q.append(v) elif color[v] == color[u]: is_bipartite = False break if is_bipartite: print("No") return # Check if D is at least V-1 if D >= V - 1: print("Yes") else: # Since we can't compute diameter efficiently, we'll assume No for D < V-1 print("No") if __name__ == "__main__": main()