Joker
Time limit2sMemory limit256 MB
Given a graph with N junctions and M streets, decide for each query [l, r] whether the streets outside that index range still contain an odd cycle.
- Level
Medium7 of 10
- Topics
- Graph, Union-find, Divide and conquer
- Solved
- No attempts yet
Problem
Joker returns to Gotham City to carry out another evil plan. Gotham City has N street junctions (numbered 1 to N) and M streets (numbered 1 to M). Each street connects two distinct junctions, and any two junctions are connected by at most one street.
For the plan, Joker must use an odd number of streets that together form a cycle. That is, for a junction S and an even positive integer k, there must be a sequence of junctions S, s1, ..., sk, S such that:
(a) a street connects S and s1, (b) a street connects sk and S, (c) a street connects s(i-1) and si for each i = 2, ..., k.
The police control the streets of Gotham City. On each day i, they monitor the streets whose numbers j satisfy li ≤ j ≤ ri. Monitored streets cannot be part of Joker's plan. Joker has a spy inside the police department, who tells him which streets are monitored each day. For a given number of days, Joker wants to know whether he can carry out the plan. On a given day, he can carry it out only if some cycle of an odd number of streets exists that uses no monitored street.
Input
The first line contains three integers N, M, and Q (1 ≤ N, M, Q ≤ 200000): the number of junctions, the number of streets, and the number of days. The next M lines describe the streets. The j-th of these lines contains two junction numbers u and v (u ≠ v), meaning street j connects these two junctions. The next Q lines each contain two integers li and ri, meaning that streets j with li ≤ j ≤ ri are monitored on that day.
Output
Print Q lines. On line i, print "YES" if Joker can carry out the plan on day i, and "NO" otherwise.
Hint

Figure 1.