CF1583E.Moment of Bloom

普及/提高-

通过率:0%

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 .

输入格式

The first line contains two integers nn and mm ( 2n31052 \leq n \leq 3 \cdot 10^5 , n1mmin(n(n1)2,3105)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 ( 1x,yn1 \leq x, y \leq n , xyx\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 ( 1q31051 \leq q \leq 3 \cdot 10^5 ).

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

It is guaranteed that nq3105nq \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.

输入输出样例

  • 输入#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.

首页