#K4836. Reach City N
Reach City N
Reach City N
Given a directed graph with \(N\) cities and \(M\) one-way routes, determine if it is possible to travel from City 1 to City \(N\) by following the specified routes. Each route is represented by an ordered pair \((u, v)\), indicating that there is a one-way route from city \(u\) to city \(v\).
Formally, you are given a directed graph \(G=(V, E)\), where \(V=\{1,2,\ldots,N\}\) and \(E\) is the set of directed edges. Determine whether there exists a path from 1 to \(N\).
inputFormat
The first line contains two integers \(N\) and \(M\), where \(N\) is the number of cities and \(M\) is the number of routes. Each of the following \(M\) lines contains two integers \(u\) and \(v\), representing a one-way route from city \(u\) to city \(v\).
outputFormat
Output a single line containing "YES" if it is possible to reach city \(N\) from city 1, or "NO" otherwise.
## sample4 4
1 2
2 3
3 4
4 2
YES