Masala D

Xotira 60 MB Vaqt 6000 ms
14

Outlining Borders

You are given an undirected graph consisting of nn ertices and mm edges. The vertices are numbered with integers from 1 to nn, the edges are numbered with integers from 1 to mm. Each edge can be unpainted or be painted in one of the kk colors, which are numbered with integers from 1 to kk. Initially, none of the edges is painted in any of the colors.

You get queries of the form "Repaint edge eie_i to color cic_i". At any time the graph formed by the edges of the same color must be bipartite. If after the repaint this condition is violated, then the query is considered to be invalid and edge eie_i keeps its color. Otherwise, edge eie_i is repainted in color cic_i, and the query is considered to valid.

Recall that the graph is called bipartite if the set of its vertices can be divided into two parts so that no edge connected vertices of the same parts.

For example, suppose you are given a triangle graph, that is a graph with three vertices and edges (1, 2), (2, 3) and (3, 1). Suppose that the first two edges are painted color 1, and the third one is painted color 2. Then the query of "repaint the third edge in color 1" will be incorrect because after its execution the graph formed by the edges of color 1 will not be bipartite. On the other hand, it is possible to repaint the second edge in color 2.

You receive qq queries. For each query, you should either apply it, and report that the query is valid, or report that the query is invalid.


Kiruvchi ma'lumotlar:

The first line contains integers n,m,k,q(2n5105,1m,q5105,1k50)n, m, k, q (2 ≤ n ≤ 5·10^5, 1 ≤ m, q ≤ 5·10^5, 1 ≤ k ≤ 50) — the number of vertices, the number of edges, the number of colors and the number of queries.

Then follow mm edges of the graph in the form ai,bi(1ai,bin).a_i, b_i (1 ≤ a_i, b_i ≤ n).

Then follow qq queries of the form ei,ci(1eim,1cik).e_i, c_i (1 ≤ e_i ≤ m, 1 ≤ c_i ≤ k).

It is guaranteed that the graph doesn't contain multiple edges and loops.


Chiquvchi ma'lumotlar:

For each query print "YES" (without the quotes), if it is valid, or "NO" (without the quotes), if this query destroys the bipartivity of the graph formed by the edges of some color.


Misollar
# input.txt output.txt
1
3 3 2 5
1 2
2 3
1 3
1 1
2 1
3 2
3 1
2 2
YES
YES
YES
NO
YES