#K15771. Kingdom Road Network Reachability

    ID: 24431 Type: Default 1000ms 256MiB

Kingdom Road Network Reachability

Kingdom Road Network Reachability

In this problem, you are given a kingdom with (n) cities and (m) one-way roads. Each road connects one city to another and is described by a pair of integers (u) and (v) indicating a road from city (u) to city (v). Formally, the road network can be modeled as a directed graph (G=(V, E)) where (V = {0, 1, \dots, n-1}) and (E) is the set of directed edges.

Your task is to determine whether there exists a route from a given source city (a) to a destination city (b). If such a route exists, print YES; otherwise, print NO.

inputFormat

The input is read from standard input (stdin) and consists of multiple lines:

  • The first line contains two integers \(n\) and \(m\), where \(n\) is the number of cities and \(m\) is the number of roads.
  • The next \(m\) lines each contain two integers \(u\) and \(v\), representing a one-way road from city \(u\) to city \(v\).
  • The last line contains two integers \(a\) and \(b\), representing the source and destination cities respectively.

outputFormat

Print a single line to standard output (stdout): YES if there exists a route from city (a) to city (b); otherwise, print NO.## sample

4 4
0 1
1 2
2 3
0 3
0 3
YES