博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 5438 Ponds(2015ACM长春网络赛+枚举删点+DFS求联通块)
阅读量:4139 次
发布时间:2019-05-25

本文共 2151 字,大约阅读时间需要 7 分钟。

Ponds

Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1026 Accepted Submission(s): 344
Problem Description
Betty owns a lot of ponds, some of them are connected with other ponds by pipes, and there will not be more than one pipe between two ponds. Each pond has a value
v .
Now Betty wants to remove some ponds because she does not have enough money. But each time when she removes a pond, she can only remove the ponds which are connected with less than two ponds, or the pond will explode.
Note that Betty should keep removing ponds until no more ponds can be removed. After that, please help her calculate the sum of the value for each connected component consisting of a odd number of ponds
Input
The first line of input will contain a number
T(1T30) which is the number of test cases.
For each test case, the first line contains two number separated by a blank. One is the number
p(1p104) which represents the number of ponds she owns, and the other is the number
m(1m105) which represents the number of pipes.
The next line contains
p numbers
v1,...,vp , where
vi(1vi108) indicating the value of pond
i .
Each of the last
m lines contain two numbers
a and
b , which indicates that pond
a and pond
b are connected by a pipe.
Output
For each test case, output the sum of the value of all connected components consisting of odd number of ponds after removing all the ponds connected with less than two pipes.
Sample Input
17 71 2 3 4 5 6 71 41 54 52 32 63 62 7
Sample Output
21
Source
//分析:题目求尽可能的不断删掉边数小于2的点 最后求所有独立子块 如果点数为奇数则加起来 否则不加
//英语差真可怕  刚开始题意错了 直接跪了... 其实不难  首先不断求出边数小于2的点 删掉 并将连接的点减1  如果减后小于2 则进队 下次删掉 最后dfs求连通块
#include 
#include
#include
#include
#include
#include
using namespace std;const int N=10000+5;vector
ve[N]; //邻接表 bool book[N]; //标记删了没 bool flag[N]; //用于求连通dfs标记用 不用回朔 int edge[N]; //点的边数 long long num[N],sum;int n,m;queue
q;int child; //用于记录每个联通块的点数 inline void del(){ int i; for(i=1;i<=n;i++) if(edge[i]<2){ q.push(i); book[i]=1; } while(!q.empty()){ int now=q.front(); q.pop(); for(i=0;i

转载地址:http://rymvi.baihongyu.com/

你可能感兴趣的文章
文件隐藏
查看>>
两个linux内核rootkit--之二:adore-ng
查看>>
两个linux内核rootkit--之一:enyelkm
查看>>
关于linux栈的一个深层次的问题
查看>>
rootkit related
查看>>
mysql-应用案例-视图的应用
查看>>
什么是虚拟机?
查看>>
Microsoft Visual C++ 和 Borland C++ Builder 之比较
查看>>
C++ Builder 中定时器的应用
查看>>
Notepad++ 是程序员的必备利器之一
查看>>
Source Insight : 程序员最得心应手的代码阅读和编辑工具(高效)
查看>>
如何用C语言获取系统的用户登录名?
查看>>
如何用C语言获取系统的sid信息?
查看>>
C/C++中如何写长串(字符数组的拼接)?
查看>>
strtok函数真是个蹩脚而又恶心的设计(千万不要嵌套使用strtok函数)
查看>>
Windows和Linux的netstat
查看>>
C++如何实现string的trim功能? (已经包含trimLeft和trimRight)
查看>>
如何确保一个函数的被调用次数不少于另外一个函数的被调用次数?
查看>>
从netstat看网络编程
查看>>
ssh, telnet在发起什么连接请求?
查看>>