CF576E.Painting Edges

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Note the unusual memory limit for this problem.

You are given an undirected graph consisting of nn vertices and mm edges. The vertices are numbered with integers from 11 to nn , the edges are numbered with integers from 11 to mm . Each edge can be unpainted or be painted in one of the kk colors, which are numbered with integers from 11 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)(1,2) , (2,3)(2,3) and (3,1)(3,1) . Suppose that the first two edges are painted color 11 , and the third one is painted color 22 . Then the query of "repaint the third edge in color 11 " will be incorrect because after its execution the graph formed by the edges of color 11 will not be bipartite. On the other hand, it is possible to repaint the second edge in color 22 .

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.

输入格式

The first line contains integers nn , mm , kk , qq ( 2<=n<=51052<=n<=5·10^{5} , 1<=m,q<=51051<=m,q<=5·10^{5} , 1<=k<=501<=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 aia_{i} , bib_{i} ( 1<=ai,bi<=n1<=a_{i},b_{i}<=n ).

Then follow qq queries of the form eie_{i} , cic_{i} ( 1<=ei<=m1<=e_{i}<=m , 1<=ci<=k1<=c_{i}<=k ).

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

输出格式

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.

输入输出样例

  • 输入#1

    3 3 2 5
    1 2
    2 3
    1 3
    1 1
    2 1
    3 2
    3 1
    2 2
    

    输出#1

    YES
    YES
    YES
    NO
    YES
    
首页