Easy
,DFS
,BFS
,Graph
1971. Find if Path Exists in Graph
There is a bi-directional graph with n
vertices, where each vertex is labeled from 0
to n - 1
(inclusive). The edges in the graph are represented as a 2D integer array edges
, where each edges[i]
= [, ] denotes a bi-directional edge between vertex and vertex . Every vertex pair is connected by at most one edge, and no vertex has an edge to itself.
You want to determine if there is a valid path that exists from vertex source
to vertex destination
.
Given edges
and the integers n
, source
, and destination
, return true
if there is a valid path from source
to destination
, or false
otherwise.
Example 1:
Example 2:
Constraints:
n
<= 2 * 105edges.length
<= 2 * 105edges[i].length
== 2n - 1
source
, destination
<= n - 1
Marsgoat Dec 19, 2022
Kobe Dec 19, 2022
玉山 Dec 21, 2022
Jim Dec 19, 2022