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 the value of and the names of the vertices. Then comes the value of and follow the arcs, made up by the name of two vertices, without repetitions nor autoloops. Then follows a pair of vertices . You can assume that and belong to the graph.
Write “yes” o “no” according to whether
there is or not a path from
to
.
Input
8 bcn prs mad rom lsb ber lon dub 10 bcn prs prs mad rom lsb rom dub ber lon lsb dub dub lsb mad lon bcn ber ber bcn bcn mad
Output
yes
Input
8 bcn prs mad rom lsb ber lon dub 10 bcn prs prs mad rom lsb rom dub ber lon lsb dub dub lsb mad lon bcn ber ber bcn rom bcn
Output
no