CF1583E.Moment of Bloom

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

She does her utmost to flawlessly carry out a person's last rites and preserve the world's balance of yin and yang.

Hu Tao, being the little prankster she is, has tried to scare you with this graph problem! You are given a connected undirected graph of nn nodes with mm edges. You also have qq queries. Each query consists of two nodes aa and bb.

Initially, all edges in the graph have a weight of 00. For each query, you must choose a simple path starting from aa and ending at bb. Then you add 11 to every edge along this path. Determine if it's possible, after processing all qq queries, for all edges in this graph to have an even weight. If so, output the choice of paths for each query.

If it is not possible, determine the smallest number of extra queries you could add to make it possible. It can be shown that this number will not exceed 101810^{18} under the given constraints.

A simple path is defined as any path that does not visit a node more than once.

An edge is said to have an even weight if its value is divisible by 22.

她竭尽全力完美地完成一个人的临终仪式,以维系世间阴阳的平衡。

身为小捣蛋鬼的胡桃,试图用这道图论题来吓唬你!你被给定一个包含 nn 个节点、mm 条边的连通无向图。此外,你还有 qq 个查询。每个查询由两个节点 aa 和 bb 组成。

初始时,图中所有边的权重均为 00。对于每个查询,你必须选择一条从 aa 出发、到 bb 结束的简单路径;然后将该路径上每条边的权重加 11。请判断:在处理完全部 qq 个查询后,图中所有边的权重是否可能均为偶数。若可能,请输出每个查询所选的路径。

若不可能,请确定最少需额外添加多少个查询才能使其成为可能。可以证明,在给定约束下,该最小数目不会超过 101810^{18}。

简单路径定义为任意不重复访问同一节点的路径。

当一条边的权值能被 22 整除时,称其具有偶数权值。

输入格式

The first line contains two integers nn and mm (2≤n≤3⋅1052 \leq n \leq 3 \cdot 10^5, n−1≤m≤min⁡(n(n−1)2,3⋅105)n-1 \leq m \leq \min{\left(\frac{n(n-1)}{2}, 3 \cdot 10^5\right)}).

Each of the next mm lines contains two integers xx and yy (1≤x,y≤n1 \leq x, y \leq n, x≠yx\neq y) indicating an undirected edge between node xx and yy. The input will not contain self-loops or duplicate edges, and the provided graph will be connected.

The next line contains a single integer qq (1≤q≤3⋅1051 \leq q \leq 3 \cdot 10^5).

Each of the next qq lines contains two integers aa and bb (1≤a,b≤n,a≠b1 \leq a, b \leq n, a \neq b), the description of each query.

It is guaranteed that nq≤3⋅105nq \leq 3 \cdot 10^5.

第一行包含两个整数 nn 和 mm(2≤n≤3⋅1052 \leq n \leq 3 \cdot 10^5,n−1≤m≤min⁡(n(n−1)2,3⋅105)n-1 \leq m \leq \min{\left(\frac{n(n-1)}{2}, 3 \cdot 10^5\right)})。

接下来的 mm 行中,每行包含两个整数 xx 和 yy(1≤x,y≤n1 \leq x, y \leq n,x≠yx\neq y),表示节点 xx 与节点 yy 之间存在一条无向边。输入中不包含自环或重复边,且所给图是连通的。

接下来一行包含一个整数 qq(1≤q≤3⋅1051 \leq q \leq 3 \cdot 10^5)。

接下来的 qq 行中,每行包含两个整数 aa 和 bb(1≤a,b≤n1 \leq a, b \leq n,a≠ba \neq b),表示每次查询的内容。

保证 nq≤3⋅105nq \leq 3 \cdot 10^5。

输出格式

If it is possible to force all edge weights to be even, print "YES" on the first line, followed by 2q2q lines indicating the choice of path for each query in the same order the queries are given. For each query, the first line should contain a single integer xx: the number of nodes in the chosen path. The next line should then contain xx spaced separated integers pip_i indicating the path you take (p1=a,px=bp_1 = a, p_x = b and all numbers should fall between 11 and nn). This path cannot contain duplicate nodes and must be a valid simple path in the graph.

If it is impossible to force all edge weights to be even, print "NO" on the first line and the minimum number of added queries on the second line.

如果可以强制使所有边的权重均为偶数,则在第一行输出“YES”,随后输出 2q2q 行,按查询给出的顺序,依次表示每个查询所选择的路径。对于每个查询,第一行应包含一个整数 xx:所选路径中的节点数;下一行应包含 xx 个用空格分隔的整数 pip_i,表示所选路径(其中 p1=ap_1 = a,px=bp_x = b,且所有数字均应在 11 到 nn 之间)。该路径不能包含重复节点,且必须是图中一条合法的简单路径。

如果无法强制使所有边的权重均为偶数,则在第一行输出“NO”,第二行输出所需额外添加的最少查询数量。

输入输出样例

  • 输入#1

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

    输出#1

    YES
    2
    1 4
    4
    5 3 2 1
    5
    4 1 2 3 5
  • 输入#2

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

    输出#2

    NO
    2

说明/提示

Here is what the queries look like for the first test case (red corresponds to the 1st query, blue 2nd query, and green 3rd query):

Notice that every edge in the graph is part of either 00 or 22 colored query edges.

The graph in the second test case looks like this:

There does not exist an assignment of paths that will force all edges to have even weights with the given queries. One must add at least 22 new queries to obtain a set of queries that can satisfy the condition.

第一个测试用例的查询如下图所示(红色对应第 1 次查询,蓝色对应第 2 次查询,绿色对应第 3 次查询):

注意:图中的每条边恰好属于 00 条或 22 条带颜色的查询边。

第二个测试用例中的图如下所示:

不存在一种路径分配方案,使得在给定查询下所有边的权重均为偶数。必须至少添加 22 个新查询,才能得到一组满足该条件的查询。

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

首页