Given a directed graph with vertices and arcs, we wish to know if there is a directed path between two given vertices.
Input starts with i . Then follow pairs , with , indicating an arc from to . We have that and and there are no repeated arcs. Then follows, a pair with and .
Write “yes” o “no” according to whether
there is or not a path from
to
.
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