55. Find if Path Exists in Graph

An undirected graph has n vertices labelled 0..n−1 and the given edges. Return whether there is a path from source to destination.

Example 1

Input: n = 3, edges = [[0,1],[1,2],[2,0]], source = 0, destination = 2
Output: true

Example 2

Input: n = 6, edges = [[0,1],[0,2],[3,5],[5,4],[4,3]], source = 0, destination = 5
Output: false
Hint 1

Build an adjacency list, then BFS or DFS from the source.

GraphBFSUnion Find