标签:col 题目 vector contain contains clu pac head example
The cows are being invaded! Their republic comprises N (1 <= N <= 50,000) towns that are connected by M (1 <= M <= 100,000) undirected paths between two towns A_i and B_i (1 <= A_i <= N; 1 <= B_i <= N; A_i != B_i; no duplicate paths will occur). However the republic is not necessarily connected--there may be pairs of towns that are unable to reach each other through the paths.
The cows know their invaders plan to conduct an inventory of every path within their republic, so they are willing to shut down various paths to make it as difficult as possible for their invaders to do so.
Please help the cows find a way to shut down a subset of the paths such that each town has an odd number of remaining paths connected to it, or determine if no such subset exists.
For example, consider the following cow republic:
1---2 \ / 3---4 If we keep the paths 1-3, 2-3, and 3-4, and remove the path 1-2, then towns 1, 2, and 4 will be an endpoint of exactly one path, whereas town 3 will be an endpoint of three paths:
1 2 \ / 3---4
* Line 1: Two space-separated integers: N and M
* Lines 2..M+1: Line i+1 contains two space-separated integers: A_i and B_i
* Line 1: A single integer that is the number of paths to keep. If no subset exists output only a single line with the integer -1.
* Lines 2..K+1: Each line contains an index of an path to keep, in the range 1..M. These indices must be pairwise distinct.
牛们正在被入侵。 有NN个点,由MM条无向边连接。 无向边从A_iAi?到B_iBi?。数据保证无重边,但不保证连通(即从一个点不一定能到达另一点)。
牛知道入侵他们的人正计划清点所有的边,所以他们想切掉一些边使入侵者的计划尽可能的困难
请找出一个方法,留下一些边,使每个点都只有奇数条边与之连接。并输出留下的边的方案。
下面是一个样例
1---2
\ /
3---4
我们把1——2那条边拆掉, 就会变成下图
1 2
\ /
3---4
对于每个点都只有奇数条边连接,符合题意
感谢@ToBiChi 提供翻译
4 4 1 2 2 3 3 1 3 4
3 2 3 4
感谢@cn:苏卿念 提供的Special Judge
思路
在图上搜索的过程中由叶子的连边情况开始更新,如果叶子上边数为奇数则证明当前选择的边不需要加入叶子的边,逆着dfs序来更新即可
CODE
P3022 [USACO11OPEN]Odd degrees G
标签:col 题目 vector contain contains clu pac head example
原文地址:https://www.cnblogs.com/orangeko/p/12556504.html