Given an undirected graph of n vertices and bidirectional edges. Determine whether there is a valid path from source to destination.
"If source == destination, we are already at the target—return true immediately in $O(1)$ time."
"Convert the edge list into an adjacency list: List<Integer>[] g. Since edges are bi-directional, add each edge in both directions."
"Seed a queue with source and mark visited[source] = true. While queue is non-empty, poll u. For each neighbor v, if v == destination, return true immediately. Otherwise mark visited[v] = true and enqueue."
"Both BFS and DSU solve this problem effectively: BFS takes $O(V + E)$ time and space; DSU takes $O(E \cdot \alpha(V))$ and is optimal when handling multiple dynamic connectivity queries."