A14646 | Moment of Bloom
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $n$ nodes with $m$ edges. You also have $q$ queries. Each query consists of two nodes $a$ and $b$ .
Initially, all edges in the graph have a weight of $0$ . For each query, you must choose a simple path starting from $a$ and ending at $b$ . Then you add $1$ to every edge along this path. Determine if it's possible, after processing all $q$ 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 $10^{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 $2$ .
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 $n$ nodes with $m$ edges. You also have $q$ queries. Each query consists of two nodes $a$ and $b$ .
Initially, all edges in the graph have a weight of $0$ . For each query, you must choose a simple path starting from $a$ and ending at $b$ . Then you add $1$ to every edge along this path. Determine if it's possible, after processing all $q$ 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 $10^{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 $2$ .
输入格式
The first line contains two integers $n$ and $m$ ( $2 \leq n \leq 3 \cdot 10^5$ , $n-1 \leq m \leq \min{\left(\frac{n(n-1)}{2}, 3 \cdot 10^5\right)}$ ).
Each of the next $m$ lines contains two integers $x$ and $y$ ( $1 \leq x, y \leq n$ , $x\neq y$ ) indicating an undirected edge between node $x$ and $y$ . The input will not contain self-loops or duplicate edges, and the provided graph will be connected.
The next line contains a single integer $q$ ( $1 \leq q \leq 3 \cdot 10^5$ ).
Each of the next $q$ lines contains two integers $a$ and $b$ ( $1 \leq a, b \leq n, a \neq b$ ), the description of each query.
It is guaranteed that $nq \leq 3 \cdot 10^5$ .
Each of the next $m$ lines contains two integers $x$ and $y$ ( $1 \leq x, y \leq n$ , $x\neq y$ ) indicating an undirected edge between node $x$ and $y$ . The input will not contain self-loops or duplicate edges, and the provided graph will be connected.
The next line contains a single integer $q$ ( $1 \leq q \leq 3 \cdot 10^5$ ).
Each of the next $q$ lines contains two integers $a$ and $b$ ( $1 \leq a, b \leq n, a \neq b$ ), the description of each query.
It is guaranteed that $nq \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 $2q$ 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 $x$ : the number of nodes in the chosen path. The next line should then contain $x$ spaced separated integers $p_i$ indicating the path you take ( $p_1 = a, p_x = b$ and all numbers should fall between $1$ and $n$ ). 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.
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 $0$ or $2$ 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 $2$ new queries to obtain a set of queries that can satisfy the condition.
 Notice that every edge in the graph is part of either $0$ or $2$ 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 $2$ new queries to obtain a set of queries that can satisfy the condition.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted