Given a directed graph of n nodes labeled from n edges where each edges[i] = [a_i, b_i] denotes a directed edge from node a_i to node b_i, along with two nodes source and destination, determine whether all paths starting from source eventually terminate at destination.
All paths starting from source lead to destination if and only if:
At least one path starts from source.
Every path starting from source ends at destination.
The node destination has no outgoing edges.
There is no cycle reachable from source that allows an infinite path.
Return true if all paths starting from source lead to destination, or false otherwise.
Constraints:
n
edges.length
edges[i].length
a_i, b_i n
source n
destination n
The given graph may have self loops and parallel edges.
Given a directed graph of n nodes labeled from n edges where each edges[i] = [a_i, b_i] denotes a directed edge from node a_i to node b_i, along with two nodes source and destination, determine whether all paths starting from source eventually terminate at destination.
All paths starting from source lead to destination if and only if:
At least one path starts from source.
Every path starting from source ends at destination.
The node destination has no outgoing edges.
There is no cycle reachable from source that allows an infinite path.
Return true if all paths starting from source lead to destination, or false otherwise.
Constraints:
n
edges.length
edges[i].length
a_i, b_i n
source n
destination n
The given graph may have self loops and parallel edges.