An undirected graph has n nodes labelled 0 .. n-1. It is given as n together with a list edges
where edges[i] = [u, v] means there is an edge between u and v. Return True if there is a path
from source to destination, otherwise False. A node always has a path to itself.
Examples
Input: n = 3, edges = [[0,1],[1,2],[2,0]], source = 0, destination = 2
Output: True
Explanation: 0 -> 2 directly, or 0 -> 1 -> 2.
Input: n = 6, edges = [[0,1],[0,2],[3,5],[5,4],[4,3]], source = 0, destination = 5
Output: False
Explanation: {0,1,2} and {3,4,5} are separate components.
Constraints
1 <= n <= 2 * 10**4,0 <= len(edges) <= 5 * 10**4- Edges may be repeated; there are no self-loops.
- Target
O(V + E)time.
Goals
- Build an adjacency list from an undirected edge list
- Run a BFS/DFS with a visited array and stop early when the destination is reached