1059. All Paths from Source Lead to Destination
https://leetcode.com/problems/all-paths-from-source-lead-to-destination
Description
Given the edges of a directed graph where edges[i] = [ai, bi] indicates there is an edge between nodes ai and bi, and two nodes source and destination of this graph, determine whether or not all paths starting from source eventually, end at destination, that is:
At least one path exists from the
sourcenode to thedestinationnodeIf a path exists from the
sourcenode to a node with no outgoing edges, then that node is equal todestination.The number of possible paths from
sourcetodestinationis a finite number.
Return true if and only if all roads from source lead to destination.
Example 1:

Example 2:

Example 3:

Example 4:

Example 5:

Constraints:
1 <= n <= 1040 <= edges.length <= 104edges.length == 20 <= ai, bi <= n - 10 <= source <= n - 10 <= destination <= n - 1The given graph may have self-loops and parallel edges.
ac
Last updated
Was this helpful?