There are n vertices and a list of undirected edges. Say whether you can walk from the vertex source to the vertex destination along the edges. Our example: 5 vertices, edges 0–1, 2–3, 1–2, from 0 to 3 → true.
input
n: the number of vertices, numbered from 0 to n - 1. edges: the undirected edges, each [u, v] joining u and v. source and destination: two vertices.
returns
true if you can walk from source to destination along the edges; otherwise false. A vertex is reached from itself.
constraints
1 ≤ n ≤ 400
0 ≤ edges.length ≤ 1000
edges[i] = [u, v], 0 ≤ u, v < n, u ≠ v
no edge is given twice, either way round
0 ≤ source, destination < n
our 11 tests keep to them
examples
Open a test in the tests panel: it shows the input and the expected answer.