CF97E.Leaders
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly order the citizens. However, leadership efficiency turned out to vary from person to person (i.e. while person A makes an efficient leader, person B may not be that good at it). That's why the dictator asked world-famous berland scientists for help. The scientists suggested an innovatory technology — to make the leaders work in pairs.
A relationship graph is some undirected graph whose vertices correspond to people. A simple path is a path with no repeated vertices. Long and frighteningly expensive research showed that a pair of people has maximum leadership qualities if a graph of relationships has a simple path between them with an odd number of edges. The scientists decided to call such pairs of different people leader pairs. Secret services provided the scientists with the relationship graph so that the task is simple — we have to learn to tell the dictator whether the given pairs are leader pairs or not. Help the scientists cope with the task.
贝兰德革命之后,新独裁者面临了一个意想不到的挑战:这个国家必须以某种方式被统治。这位独裁者是一位非常高效的管理者,但他无法亲自向每一位公民下达命令。因此,他决定挑选出一个领导者集合,由这些领导者直接向公民发号施令。然而,领导效能因人而异(例如,A 作为领导者效率很高,而 B 却可能并不擅长)。正因如此,独裁者向世界闻名的贝兰德科学家们寻求帮助。科学家们提出了一项创新技术——让领导者以两人一组的方式协同工作。
关系图是一个无向图,其顶点对应于人。简单路径是指不重复经过任何顶点的路径。漫长且令人望而生畏的昂贵研究表明:当关系图中存在一条连接两个人、且边数为奇数的简单路径时,该二人组便具有最高的领导素质。科学家们将这种不同的二人组称为领导者对(leader pairs)。秘密部门已向科学家们提供了关系图,从而使任务变得简单——我们只需判断给定的若干对人是否为领导者对。请帮助科学家们完成这项任务。
输入格式
The first line contains integers n and m (1 ≤ n ≤ 105, 0 ≤ m ≤ 105) — the number of vertices and edges in the relationship graph correspondingly. Next m lines contain pairs of integers a and b which mean that there is an edge between the a-th and the b-th vertices (the vertices are numbered starting from 1, 1 ≤ a, b ≤ n). It is guaranteed that the graph has no loops or multiple edges.
Next line contains number q (1 ≤ q ≤ 105) — the number of pairs the scientists are interested in. Next q lines contain these pairs (in the same format as the edges, the queries can be repeated, a query can contain a pair of the identical vertices).
第一行包含两个整数 n 和 m(1≤n≤105,0≤m≤105),分别表示关系图中的顶点数和边数。接下来的 m 行每行包含一对整数 a 和 b,表示第 a 个顶点与第 b 个顶点之间存在一条边(顶点编号从 1 开始,1≤a,b≤n)。保证该图不含自环或重边。
接下来一行包含一个整数 q(1≤q≤105),表示科学家感兴趣的顶点对数量。随后的 q 行每行包含一个这样的顶点对(格式与边的输入相同;查询可能重复;某个查询也可能包含两个相同的顶点)。
输出格式
For each query print on a single line "Yes" if there's a simple odd path between the pair of people; otherwise, print "No".
对于每个查询,如果两人之间存在一条简单的奇数长度路径,则在一行中输出“Yes”;否则输出“No”。
输入输出样例
输入#1
7 7 1 3 1 4 2 3 2 4 5 6 6 7 7 5 8 1 2 1 3 1 4 2 4 1 5 5 6 5 7 6 7
输出#1
No Yes Yes Yes No Yes Yes Yes
说明/提示
Notes to the samples:
-
Between vertices 1 and 2 there are 2 different simple paths in total: 1-3-2 and 1-4-2. Both of them consist of an even number of edges.
-
Vertices 1 and 3 are connected by an edge, that's why a simple odd path for them is 1-3.
-
Vertices 1 and 5 are located in different connected components, there's no path between them.
样例说明:
-
顶点 1 与顶点 2 之间共有 2 条不同的简单路径:1-3-2 和 1-4-2。这两条路径均包含偶数条边。
-
顶点 1 与顶点 3 由一条边直接相连,因此它们的一条简单奇路径为 1-3。
-
顶点 1 与顶点 5 位于不同的连通分量中,二者之间不存在路径。
输入解题思路,AI测评打分。不知道怎么写?