#K92782. Network Connectivity Queries

    ID: 38274 Type: Default 1000ms 256MiB

Network Connectivity Queries

Network Connectivity Queries

You are given a directed network of n computers labeled from \(1\) to \(n\) and m one-way communication channels. Each channel is described by a pair of integers \(u\) and \(v\), representing a channel from computer \(u\) to computer \(v\).

You will also receive q queries. Each query gives two computers \(a\) and \(b\), and your task is to determine whether there exists a path from \(a\) to \(b\) in the network. Output YES if a path exists and NO otherwise.

You may use standard graph traversal techniques such as Breadth-first Search (BFS) or Depth-first Search (DFS) to solve this problem.

inputFormat

The input is given from standard input (stdin) with the following format:

  • The first line contains three integers \(n\), \(m\), and \(q\): the number of computers, the number of communication channels, and the number of queries, respectively.
  • The next \(m\) lines each contain two integers \(u\) and \(v\), representing a directed edge from computer \(u\) to computer \(v\).
  • The following \(q\) lines each contain two integers \(a\) and \(b\), where each pair represents a query asking if there is a path from computer \(a\) to computer \(b\).

outputFormat

For each query, print a single line to standard output (stdout) containing YES if there exists a path from \(a\) to \(b\), or NO otherwise.

## sample
5 4 3
1 2
2 3
3 4
4 5
1 5
2 4
5 1
YES

YES NO

</p>