networkx
Given a directed graph with n vertices and m arcs, we wish to know if there is a directed path between two given vertices.
Input
Input starts with n and m. Then follow m pairs u,v, with u ≠ v, indicating an arc from u to v. We have that 0 ≤ u < n and 0 ≤ v < n and that there are no repeated arcs. Then follows a pair x, y with 0 ≤ x < n and 0 ≤ y < n.
Output
Write “yes” or “no” according to whether there is a path from x to y.
Observation
We are authorized to employ the NetworkX library.
Input
8 10 1 4 4 6 7 2 7 5 0 3 2 5 5 2 6 3 1 0 0 1 1 3
Output
yes
Input
8 10 1 4 4 6 7 2 7 5 0 3 2 5 5 2 6 3 1 0 0 1 7 6
Output
no