PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SRD0000085. Joker (Joker)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Joker (Joker)

Joker

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You are given a simple undirected graph with NN vertices numbered from 1 to NN and MM edges numbered in input order. Every edge joins distinct vertices, and no unordered pair occurs more than once. On day ii, the edges indexed by the inclusive interval [li,ri][l_i,r_i] are monitored and cannot be used. Consider the graph formed by all remaining edges. Joker can carry out his plan if and only if this graph has an odd-length cycle. Decide this independently for every day; edge removal does not persist into later days.

Input

The first line contains N,M,QN,M,Q. Each of the next MM lines contains the endpoints u,vu,v of one indexed edge, followed by QQ lines li,ril_i,r_i. All indices are 1-based.

Output

Print YES if the remaining graph contains an odd cycle, otherwise print NO, one answer per query.

Subtasks

  • Subtask 1 (6 points): 1≤N≤2001\le N\le 200; 1≤M≤2001\le M\le 200; 1≤Q≤2001\le Q\le 200. 1≤N,M,Q≤2000001\le N,M,Q\le 200000; 1≤u,v≤N1\le u,v\le N, u≠vu\ne v; no repeated edges; 1≤li≤ri≤M1\le l_i\le r_i\le M.

  • Subtask 2 (8 points): 1≤N≤20001\le N\le 2000; 1≤M≤20001\le M\le 2000; 1≤Q≤20001\le Q\le 2000. 1≤N,M,Q≤2000001\le N,M,Q\le 200000; 1≤u,v≤N1\le u,v\le N, u≠vu\ne v; no repeated edges; 1≤li≤ri≤M1\le l_i\le r_i\le M.

  • Subtask 3 (25 points): 1≤N≤2000001\le N\le 200000; 1≤M≤2000001\le M\le 200000; 1≤Q≤2000001\le Q\le 200000. 1≤N,M,Q≤2000001\le N,M,Q\le 200000; 1≤u,v≤N1\le u,v\le N, u≠vu\ne v; no repeated edges; 1≤li≤ri≤M1\le l_i\le r_i\le M. li=1l_i=1 for every query.

  • Subtask 4 (10 points): 1≤N≤2000001\le N\le 200000; 1≤M≤2000001\le M\le 200000; 1≤Q≤2000001\le Q\le 200000. 1≤N,M,Q≤2000001\le N,M,Q\le 200000; 1≤u,v≤N1\le u,v\le N, u≠vu\ne v; no repeated edges; 1≤li≤ri≤M1\le l_i\le r_i\le M. li≤200l_i\le 200 for every query.

  • Subtask 5 (22 points): 1≤N≤2000001\le N\le 200000; 1≤M≤2000001\le M\le 200000; 1≤Q≤20001\le Q\le 2000. 1≤N,M,Q≤2000001\le N,M,Q\le 200000; 1≤u,v≤N1\le u,v\le N, u≠vu\ne v; no repeated edges; 1≤li≤ri≤M1\le l_i\le r_i\le M.

  • Subtask 6 (29 points): 1≤N≤2000001\le N\le 200000; 1≤M≤2000001\le M\le 200000; 1≤Q≤2000001\le Q\le 200000. 1≤N,M,Q≤2000001\le N,M,Q\le 200000; 1≤u,v≤N1\le u,v\le N, u≠vu\ne v; no repeated edges; 1≤li≤ri≤M1\le l_i\le r_i\le M.

Examples

Input

6 8 2
1 3
1 5
1 6
2 5
2 6
3 4
3 5
5 6
4 8
4 7

Output

NO
YES

Explanation

On the first day only edges 1 to 3 remain; the graph is bipartite, hence there is no odd cycle (NO). On the second day edges 4 to 7 are removed; remaining edges 1,2,3,8 include triangle 1−5−6−11-5-6-1, so the answer is YES.