All Paths from Source Lead to Destination
Given theedgesof a directed graph, and two nodessourceanddestinationof this graph, determine whether or not all paths starting fromsourceeventually end atdestination, that is:
At least one path exists from the
sourcenode to the
destinationnode
If a path exists from the
sourcenode to a node with no outgoing edges, then that node is equal to
destination.
The number of possible paths from
sourceto
destinationis a finite number.
Returntrueif and only if all roads fromsourcelead todestination.
Example 1:

Example 2:

Example 3:

Example 4:

Example 5:

Note:
分析
一条道带一个path(set), 在子dfs前加入,loop完了去掉。有回溯
不是起点也不是终点,返错,要不继续往下探索
Last updated
Was this helpful?