#K49832. Server Network Message Transmission
Server Network Message Transmission
Server Network Message Transmission
You are given a network containing n servers and m bidirectional communication links. Each link connects two distinct servers. You are also given q queries. In each query, you are given a pair of servers, and your task is to determine whether there exists a communication path between them so that a message can be transmitted.
The network can be represented as an undirected graph where the nodes correspond to servers and the edges correspond to communication links. Two servers a and b are connected if there exists a path in the graph connecting them.
Mathematically, if we denote the servers by numbers from 1 to n, and the links as unordered pairs, you need to answer for each query whether there exists a path from server a to server b. The problem formally requires you to decide the connectivity between two nodes in an undirected graph.
For the mathematical formulation, let \(G = (V, E)\) be an undirected graph where \(V = \{1, 2, \ldots, n\}\) and \(E\) is a set of unordered pairs representing links. For each query \((a, b)\), output yes if \(\exists\; path\; from\; a \; to\; b\) in \(G\), otherwise output no.
inputFormat
The input is given in the following format from stdin:
n m q u1 v1 ... um vm a1 b1 ... aq bq
Where:
- n is the number of servers.
- m is the number of communication links.
- q is the number of queries.
- Each of the next m lines contains two integers u and v (1-indexed) which indicates that there is a bidirectional link between server u and server v.
- Each of the next q lines contains two integers a and b representing a query asking if there is any path between server a and server b.
outputFormat
For each query, print a single line to stdout containing yes
if a message can be transmitted between the two given servers, or no
if it cannot.
5 4 3
1 2
2 3
3 4
4 5
1 5
2 4
5 1
yes
yes
yes
</p>