#P10648. Island Alliance
Island Alliance
Island Alliance
There are n islands on the sea. Some pairs of islands have hostile relationships. Due to harsh weather conditions, no island can survive alone, so some islands propose to form alliances.
Initially, each island is its own alliance. You are given m pairs of islands that have a hostile (\(\textbf{bad}\)) relationship. Then, there are q alliance requests. Each request consists of a pair \((a_i,b_i)\), meaning that island \(a_i\) wants to form an alliance with island \(b_i\).
An alliance request is approved if and only if every island in the alliance containing \(a_i\) has no hostile relationship with every island in the alliance containing \(b_i\). In other words, for every \(x\) in alliance \(A\) (containing \(a_i\)) and every \(y\) in alliance \(B\) (containing \(b_i\)), the pair \((x,y)\) must not be one of the hostile pairs. If the condition holds, the two alliances merge immediately; otherwise, the request is rejected.
For each alliance request, print YES
if the alliance is approved (and merge the alliances if they were separate), or NO
if the request is rejected.
inputFormat
The first line contains three integers: n, m, and q — the number of islands, the number of hostile pairs, and the number of alliance requests, respectively.
The next m lines each contain two integers u and v (1-indexed), indicating that island u and island v have a hostile relationship.
The following q lines each contain two integers ai and bi representing an alliance request between the alliances containing island ai and island bi.
outputFormat
Output q lines. For each alliance request, output YES
if the alliance is approved (and the alliances are merged if they were separate), or NO
if the request is rejected due to a hostile relationship.
sample
5 2 4
1 2
3 4
1 3
2 4
1 2
1 5
YES
YES
NO
YES
</p>