CF639F.Bear and Chemistry

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Limak is a smart brown bear who loves chemistry, reactions and transforming elements.

In Bearland (Limak's home) there are nn elements, numbered 11 through nn . There are also special machines, that can transform elements. Each machine is described by two integers ai,bia_{i},b_{i} representing two elements, not necessarily distinct. One can use a machine either to transform an element aia_{i} to bib_{i} or to transform bib_{i} to aia_{i} . Machines in Bearland aren't very resistant and each of them can be used at most once. It is possible that ai=bia_{i}=b_{i} and that many machines have the same pair ai,bia_{i},b_{i} .

Radewoosh is Limak's biggest enemy and rival. He wants to test Limak in the chemistry. They will meet tomorrow and both of them will bring all their machines. Limak has mm machines but he doesn't know much about his enemy. They agreed Radewoosh will choose two distinct elements, let's denote them as xx and yy . Limak will be allowed to use both his and Radewoosh's machines. He may use zero or more (maybe even all) machines to achieve the goal, each machine at most once. Limak will start from an element xx and his task will be to first get an element yy and then to again get an element xx — then we say that he succeeds. After that Radewoosh would agree that Limak knows the chemistry (and Radewoosh would go away).

Radewoosh likes some particular non-empty set of favorite elements and he will choose x,yx,y from that set. Limak doesn't know exactly which elements are in the set and also he doesn't know what machines Radewoosh has. Limak has heard qq gossips (queries) though and each of them consists of Radewoosh's machines and favorite elements. For each gossip Limak wonders if he would be able to succeed tomorrow for every pair x,yx,y chosen from the set of favorite elements. If yes then print "YES" (without the quotes). But if there exists a pair (x,y)(x,y) from the given set that Limak wouldn't be able to succeed then you should print "NO" (without the quotes).

输入格式

The first line contains three integers nn , mm and qq ( 1<=n,q<=300000,0<=m<=3000001<=n,q<=300000,0<=m<=300000 ) — the number of elements, the number of Limak's machines and the number of gossips, respectively.

Each of the next mm lines contains two integers aia_{i} and bib_{i} ( 1<=ai,bi<=n1<=a_{i},b_{i}<=n ) describing one of Limak's machines.

Then, the description of qq gossips follows.

The first line of the description of the ii -th gossip contains two integers nin_{i} and mim_{i} ( 1<=ni<=300000,0<=mi<=3000001<=n_{i}<=300000,0<=m_{i}<=300000 ). The second line contains nin_{i} distinct integers xi,1,xi,2,...,xi,nix_{i,1},x_{i,2},...,x_{i,ni} ( 1<=xi,j<=n1<=x_{i,j}<=n ) — Radewoosh's favorite elements in the ii -th gossip. Note that ni=1n_{i}=1 is allowed, in this case there are no pairs of distinct elements, so Limak automatically wins (the answer is "YES"). Then mim_{i} lines follow, each containing two integers ai,j,bi,ja_{i,j},b_{i,j} ( 1<=ai,j,bi,j1<=a_{i,j},b_{i,j} ) describing one of Radewoosh's machines in the ii -th gossip.

The sum of nin_{i} over all gossips won't exceed 300000300000 . Also, the sum of mim_{i} over all gossips won't exceed 300000300000 .

Important: Because we want you to process the gossips online, in order to know the elements in Radewoosh's favorite set and elements that his machines can transform, for on each number that denotes them in the input you should use following function:

int rotate(int element)
{
   element=(element+R)%n;

   if (element==0) {
       element=n;
   }

   return element;
}

where RR is initially equal to 00 and is increased by the number of the query any time the answer is "YES". Queries are numbered starting with 11 in the order they appear in the input.

输出格式

You should print qq lines. The ii -th of them should contain "YES" (without quotes) if for the ii -th gossip for each pair of elements xx and yy (in the set xi,1,xi,2,...,xi,nix_{i,1},x_{i,2},...,x_{i,ni} ) Limak is able to succeed. Otherwise you should print "NO" (without quotes).

输入输出样例

  • 输入#1

    6 5 4
    1 2
    2 3
    3 4
    2 4
    5 6
    2 0
    4 2
    2 1
    6 2
    3 4
    3 2
    6 3 4
    2 5
    4 6
    2 1
    1 2
    1 2
    

    输出#1

    YES
    NO
    YES
    YES
    
  • 输入#2

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

    输出#2

    NO
    YES
    

说明/提示

Lets look at first sample:

In first gossip Radewoosh's favorite set is 4,2{4,2} and he has no machines. Limak can tranform element 44 into 22 (so half of a task is complete) and then 22 into 33 , and 33 into 44 . Answer is "YES", so RR is increased by 11 .

In second gossip set in the input is denoted by 6,2{6,2} and machine by (3,4)(3,4) , but RR is equal to 11 , so set is 1,3{1,3} and machine is (4,5)(4,5) . Answer is "NO", so RR isn't changed.

In third gossip set 6,4,3{6,4,3} and machines (2,5)(2,5) and (4,6)(4,6) are deciphered to be 1,5,4{1,5,4} , (3,6)(3,6) and (5,1)(5,1) .

Consider Radewoosh's choices:

  • If he chooses elements 11 and 55 , then Limak is able to transform 11 into 55 , then 66 into 33 , 33 into 22 and 22 into 11 .
  • If he chooses elements 55 and 44 , then Limak is able to transform 55 into 66 , 66 into 33 , 33 into 44 (half way already behind him), 44 into 22 , 22 into 11 , 11 into 55 .
  • If he chooses elements 11 and 44 , then Limak is able to transform 11 into 22 , 22 into 44 , 44 into 33 , 33 into 66 , 66 into 55 and 55 into 11 .

So Limak is able to execute task. Answer is "YES" and RR is increased by 33 (it's equal to 44 now).

In last gossip 1,2{1,2} and (1,2)(1,2) are deciphered to be 5,6{5,6} and (5,6)(5,6) . Now there are 22 machines (5,6)(5,6) so Limak is able to execute task again.

首页