CF639F.Bear and Chemistry

NOI/NOI+/CTSC

通过率:0%

时间限制:6.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

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

In Bearland (Limak's home) there are n elements, numbered 1 through n. There are also special machines, that can transform elements. Each machine is described by two integers a__i, b__i representing two elements, not necessarily distinct. One can use a machine either to transform an element a__i to b__i or to transform b__i to a__i. Machines in Bearland aren't very resistant and each of them can be used at most once. It is possible that a__i = b__i and that many machines have the same pair a__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 m machines but he doesn't know much about his enemy. They agreed Radewoosh will choose two distinct elements, let's denote them as x and y. 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 x and his task will be to first get an element y and then to again get an element x — 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, 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 q 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, y chosen from the set of favorite elements. If yes then print "YES" (without the quotes). But if there exists a pair (x, y) from the given set that Limak wouldn't be able to succeed then you should print "NO" (without the quotes).

Limak 是一只聪明的棕色熊,他热爱化学、化学反应以及元素转化。

在熊国(Limak 的故乡)中,共有 nn 种元素,编号为 11 到 nn。此外,还存在一些特殊的机器,可用于转化元素。每台机器由两个整数 ai, bia_i,\,b_i 描述,分别代表两种元素(二者未必不同)。一台机器可用于将元素 aia_i 转化为 bib_i,也可用于将 bib_i 转化为 aia_i。熊国的机器并不十分耐用,每台机器最多只能使用一次。可能出现 ai=bia_i = b_i 的情况,也可能有多台机器具有相同的数对 (ai, bi)(a_i,\,b_i)。

Radewoosh 是 Limak 最大的敌人与对手。他想通过化学知识来考验 Limak。他们约定明天见面,双方都会带上自己所有的机器。Limak 拥有 mm 台机器,但他对敌人的机器一无所知。双方约定:Radewoosh 将从某个非空的“喜爱元素集合”中选出两个互异的元素,记为 xx 和 yy。而 Limak 被允许同时使用他自己和 Radewoosh 的所有机器;他可以使用零台或多台(甚至全部)机器来达成目标,但每台机器至多使用一次。Limak 将从元素 xx 出发,其任务是先得到元素 yy,再回到元素 xx —— 此时我们称他成功。若成功,Radewoosh 就会承认 Limak 掌握了化学知识(并离开)。

Radewoosh 喜欢某个特定的非空喜爱元素集合,他将总是从该集合中选择 x, yx,\,y。Limak 并不知道该集合具体包含哪些元素,也不知道 Radewoosh 拥有哪些机器。不过,Limak 听到了 qq 条流言(即 qq 个查询),每条流言都包含 Radewoosh 的机器列表及他的喜爱元素集合。对于每条流言,Limak 都想知道:是否对喜爱元素集合中的任意一对互异元素 (x, y)(x,\,y),他都能保证成功? 若答案为是,则输出 "YES"(不带引号);若存在某一对 (x, y)(x,\,y)(其中 x,yx,y 均属于给定的喜爱元素集合且 x≠yx \ne y),使得 Limak 无法成功,则输出 "NO"(不带引号)。

输入格式

The first line contains three integers n, m and q (1 ≤ n, q ≤ 300 000, 0 ≤ m ≤ 300 000) — the number of elements, the number of Limak's machines and the number of gossips, respectively.

Each of the next m lines contains two integers a__i and b__i (1 ≤ a__i, b__i ≤ n) describing one of Limak's machines.

Then, the description of q gossips follows.

The first line of the description of the i-th gossip contains two integers n__i and m__i (1 ≤ n__i ≤ 300 000, 0 ≤ m__i ≤ 300 000). The second line contains n__i distinct integers x__i, 1, x__i, 2, ..., x__i, n__i (1 ≤ x__i, j ≤ n) — Radewoosh's favorite elements in the i-th gossip. Note that n__i = 1 is allowed, in this case there are no pairs of distinct elements, so Limak automatically wins (the answer is "YES"). Then m__i lines follow, each containing two integers a__i, j, b__i, j (1 ≤ a__i, j, b__i, j) describing one of Radewoosh's machines in the i-th gossip.

The sum of n__i over all gossips won't exceed 300 000. Also, the sum of m__i over all gossips won't exceed 300 000.

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 R is initially equal to 0 and is increased by the number of the query any time the answer is "YES". Queries are numbered starting with 1 in the order they appear in the input.

第一行包含三个整数 nn、mm 和 qq(1≤n,q≤300 0001 \leq n, q \leq 300\,000,0≤m≤300 0000 \leq m \leq 300\,000),分别表示元素个数、Limak 的机器数量以及八卦消息的数量。

接下来的 mm 行中,每行包含两个整数 aia_i 和 bib_i(1≤ai,bi≤n1 \leq a_i, b_i \leq n),描述 Limak 的一台机器。

随后是 qq 条八卦消息的描述。

第 ii 条八卦消息的描述以一行开头,包含两个整数 nin_i 和 mim_i(1≤ni≤300 0001 \leq n_i \leq 300\,000,0≤mi≤300 0000 \leq m_i \leq 300\,000)。下一行包含 nin_i 个互不相同的整数 xi,1,xi,2,…,xi,nix_{i,1}, x_{i,2}, \dots, x_{i,n_i}(1≤xi,j≤n1 \leq x_{i,j} \leq n),表示第 ii 条八卦消息中 Radewoosh 最喜欢的元素。注意,当 ni=1n_i = 1 时是允许的;此时不存在任意一对不同的元素,因此 Limak 自动获胜(答案为 "YES")。接着是 mim_i 行,每行包含两个整数 ai,ja_{i,j}、bi,jb_{i,j}(1≤ai,j,bi,j≤n1 \leq a_{i,j}, b_{i,j} \leq n),描述第 ii 条八卦消息中 Radewoosh 的一台机器。

所有八卦消息中 nin_i 的总和不超过 300 000300\,000;同样,所有八卦消息中 mim_i 的总和也不超过 300 000300\,000。

重要提示:由于要求你在线处理这些八卦消息,为了确定 Radewoosh 喜欢的元素集合中的元素及其机器可变换的元素,对于输入中表示这些元素的每个数字,你都应使用如下函数:

int rotate(int element)  
{  
    element = (element + R) % n;  
  
    if (element == 0) {  
        element = n;  
    }  
  
    return element;  
}

其中 RR 初始值为 00,且每当某次查询的答案为 "YES" 时,RR 就增加该查询的编号(查询按输入顺序从 11 开始编号)。

输出格式

You should print q lines. The i-th of them should contain "YES" (without quotes) if for the i-th gossip for each pair of elements x and y (in the set x__i, 1, x__i, 2, ..., x__i, n__i) Limak is able to succeed. Otherwise you should print "NO" (without quotes).

你需要输出 q 行。其中第 i 行应为 "YES"(不带引号),当且仅当对于第 i 个八卦,Limak 能够对集合 {x__i, 1, x__i, 2, ..., x__i, n__i} 中的每一对元素 x 和 y 都成功完成;否则应输出 "NO"(不带引号)。

输入输出样例

  • 输入#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} and he has no machines. Limak can tranform element 4 into 2 (so half of a task is complete) and then 2 into 3, and 3 into 4. Answer is "YES", so R is increased by 1.

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

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

Consider Radewoosh's choices:

  • If he chooses elements 1 and 5, then Limak is able to transform 1 into 5, then 6 into 3, 3 into 2 and 2 into 1.
  • If he chooses elements 5 and 4, then Limak is able to transform 5 into 6, 6 into 3, 3 into 4 (half way already behind him), 4 into 2, 2 into 1, 1 into 5.
  • If he chooses elements 1 and 4, then Limak is able to transform 1 into 2, 2 into 4, 4 into 3, 3 into 6, 6 into 5 and 5 into 1.

So Limak is able to execute task. Answer is "YES" and R is increased by 3 (it's equal to 4 now).

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

我们来看第一个样例:

在第一次流言中,Radewoosh 最喜欢的集合是 {4, 2}\{4,\,2\},且他没有任何机器。Limak 可以将元素 44 变为 22(因此任务完成了一半),然后将 22 变为 33,再将 33 变为 44。答案为 “YES”,因此 RR 增加 11。

在第二次流言中,输入中给出的集合记为 {6, 2}\{6,\,2\},机器记为 (3, 4)(3,\,4),但此时 R=1R = 1,因此该集合被解密为 {1, 3}\{1,\,3\},机器被解密为 (4, 5)(4,\,5)。答案为 “NO”,故 RR 保持不变。

在第三次流言中,集合 {6, 4, 3}\{6,\,4,\,3\} 和机器 (2, 5)(2,\,5)、(4, 6)(4,\,6) 被解密为 {1, 5, 4}\{1,\,5,\,4\}、(3, 6)(3,\,6) 和 (5, 1)(5,\,1)。

考虑 Radewoosh 的所有选择:

  • 若他选择元素 11 和 55,则 Limak 能够将 11 变为 55,再将 66 变为 33,33 变为 22,22 变为 11;
  • 若他选择元素 55 和 44,则 Limak 能够将 55 变为 66,66 变为 33,33 变为 44(此时任务已过半),再将 44 变为 22,22 变为 11,11 变为 55;
  • 若他选择元素 11 和 44,则 Limak 能够将 11 变为 22,22 变为 44,44 变为 33,33 变为 66,66 变为 55,55 变为 11。

因此 Limak 能够完成该任务。答案为 “YES”,且 RR 增加 33(此时 R=4R = 4)。

在最后一次流言中,{1, 2}\{1,\,2\} 和 (1, 2)(1,\,2) 被解密为 {5, 6}\{5,\,6\} 和 (5, 6)(5,\,6)。此时共有 22 台机器 (5, 6)(5,\,6),因此 Limak 再次能够完成任务。

输入解题思路,AI测评打分。不知道怎么写?

首页