You are given a directed acyclic graph with vertices and edges. The -th edge goes from vertex to vertex . Initially, every vertex is reachable from vertex .
You may remove at most one edge. After the removal, there must be at most one directed path from vertex to each vertex.
Find the maximum number of vertices that can remain reachable from vertex , or report that this is impossible. Vertex itself is considered reachable.
if it is impossible.
No edge needs to be removed. All four vertices are reachable, and each has a unique path from vertex .
There are two paths from vertex to vertex and two paths from vertex to vertex . The edges used by these two pairs are disjoint, so removing one edge cannot fix both.
The only vertex is vertex , which is reachable.
Remove the edge . All four vertices remain reachable, and each has a unique path from vertex .
Remove the edge . Exactly vertices , , and remain reachable, each by a unique path. Every other single-edge removal leaves two paths to vertex or vertex , so the answer is .