#C5508. Path Existence Query
Path Existence Query
Path Existence Query
You are given a directed graph representing connections between servers. The graph has n servers and m directed edges. You are also given q queries. Each query asks whether there exists a path from a starting server to an ending server using the provided connections.
Formally, you are given integers \(n, m, q\) where \(n, m, q \in \mathbb{Z}^{+}\). Then you are given \(m\) pairs of integers \((u, v)\) representing a directed edge from server \(u\) to server \(v\). Finally, you are given \(q\) pairs of integers \((a, b)\) for which you need to determine if there exists a sequence of directed edges starting at \(a\) and ending at \(b\).
You should output "YES" if a path exists for a query, and "NO" otherwise.
inputFormat
The input is given via stdin and has the following format:
n m q u1 v1 u2 v2 ... (m lines in total) a1 b1 a2 b2 ... (q lines in total)
Here, the first line contains three integers: n (number of servers), m (number of directed connections), and q (number of queries). The next m lines each contain two integers \(u\) and \(v\) representing a directed edge from server \(u\) to server \(v\). The following q lines each contain two integers \(a\) and \(b\), representing a query to check if a path exists from server \(a\) to server \(b\).
outputFormat
For each query, output a single line to stdout. Print "YES" if a path exists from the starting server to the ending server, otherwise print "NO".
## sample4 4 3
1 2
2 3
3 4
1 3
1 4
4 1
2 4
YES
NO
YES
</p>