Find if Path Exists in Graph
Easy
LC #1971
dfsbfsconnectivityNot attempted yet
You get an undirected graph with n nodes labelled
0..n-1 as a list of edges ([u, v] pairs). Return
True if there is a path from source to
destination, otherwise False.
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
{0, 1, 2} and {3, 4, 5} are separate components.
Constraints
1 <= n <= 2 * 10^40 <= len(edges) <= 2 * 10^4- no duplicate edges and no self-loops