这题主要是个套路。。就是求无向图最小路径覆盖。。
与有向图的二分图做法不同,这个是转化为求最少的欧拉路径。。
欧拉图有个结论是欧拉路径的个数为度为奇数的点的个数/2(可以类比欧拉回路的结论)
然后求欧拉路径的方法是fleury算法。。其思想就是暴力dfs,然后巧妙的地方就是边是方向取的,即以出栈的顺序为欧拉路径。。
然后就是一大堆细节问题。。大概是今天没什么人做出来的原因。。。
这题其实覆盖得情况比较全面(偶数的欧拉回路,奇数的欧拉回路和欧拉路径、分块求欧拉路径等),作为模板其实挺合适。。可以记下来。。
/**
* ┏┓ ┏┓
* ┏┛┗━━━━━━━┛┗━━━┓
* ┃ ┃
* ┃ ━ ┃
* ┃ > < ┃
* ┃ ┃
* ┃... ⌒ ... ┃
* ┃ ┃
* ┗━┓ ┏━┛
* ┃ ┃ Code is far away from bug with the animal protecting
* ┃ ┃ 神兽保佑,代码无bug
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┗━━━┓
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━━━━━━━━┳┓┏┛
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛
*/
#include
#include
#include
#include
#include
#include
#include
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 225 Accepted Submission(s): 36
Special Judge
Problem Description
The Wall has down and the King in the north has to send his soldiers to sentinel.
The North can be regard as a undirected graph (not necessary to be connected), one soldier can cover one path. Today there's no so many people still breathing in the north, so the King wants to minimize the number of soldiers he sent to cover each edge exactly once. As a master of his, you should tell him how to arrange soldiers.
Input
There might be multiple test cases, no more than 20. You need to read till the end of input.
In the first line, two integers n and m, representing the number of nodes and edges in the graph.
In the following m lines, each contain two integers, representing two ends of an edge.
There are no parallel edges or self loops.
1≤n,m≤100000
Output
For each test case, the first line contains number of needed routes, p.
For the following p lines, an integer x in the beginning, followed by x integers, representing the list of used edges. Every integer should be a positive or negative integer. Its absolute value represents the number of chosen edge (1~n). If it's positive, it shows that this edge should be passed as the direction as the input, otherwise this edge should be passed in the direction different from the input. Edges should be in correct order.
Sample Input
3 3 1 2 1 3 2 3
Sample Output
1 3 1 3 -2
Source
2018 Multi-University Training Contest 2
Recommend
chendu | We have carefully selected several similar problems for you: 6318 6317 6316 6315 6314
Statistic | Submit | Discuss | Note