Is there a path
A graph is a set of nodes joined by edges. This graph has n nodes, numbered 0 to n - 1. Each item [a, b] in the list edges is a two-way edge: you can step from a to b and from b to a.
Return True if you can get from node source to node destination by stepping along edges, and False if you cannot. Every node can reach itself, so when source equals destination the answer is True.
No edge is listed twice, and no edge joins a node to itself.
n = 6, edges = [[0, 1], [0, 2], [1, 3], [2, 3], [4, 5]], source = 0, destination = 3OutputTrueStep from 0 to 1, then from 1 to 3.
n = 6, edges = [[0, 1], [0, 2], [1, 3], [2, 3], [4, 5]], source = 1, destination = 5OutputFalseNodes 4 and 5 are joined only to each other. No edge links them to nodes 0 to 3.
n = 1, edges = [], source = 0, destination = 0OutputTrueNo step is needed to stay at node 0.
1 ≤ n ≤ 2 × 105
0 ≤ len(edges) ≤ 2 × 105
Each edge is
[a, b]with0 ≤ a, b ≤ n - 1anda != b. No edge is listed twice.0 ≤ source, destination ≤ n - 1
Plan it first
Write a line for each before you code, then say them out loud. Compare with the Approach tab afterwards.