博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 2378 Tree Cutting
阅读量:6923 次
发布时间:2019-06-27

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

Tree Cutting
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 3525   Accepted: 2083

Description

After Farmer John realized that Bessie had installed a "tree-shaped" network among his N (1 <= N <= 10,000) barns at an incredible cost, he sued Bessie to mitigate his losses. 
Bessie, feeling vindictive, decided to sabotage Farmer John's network by cutting power to one of the barns (thereby disrupting all the connections involving that barn). When Bessie does this, it breaks the network into smaller pieces, each of which retains full connectivity within itself. In order to be as disruptive as possible, Bessie wants to make sure that each of these pieces connects together no more than half the barns on FJ. 
Please help Bessie determine all of the barns that would be suitable to disconnect.

Input

* Line 1: A single integer, N. The barns are numbered 1..N. 
* Lines 2..N: Each line contains two integers X and Y and represents a connection between barns X and Y.

Output

* Lines 1..?: Each line contains a single integer, the number (from 1..N) of a barn whose removal splits the network into pieces each having at most half the original number of barns. Output the barns in increasing numerical order. If there are no suitable barns, the output should be a single line containing the word "NONE".

Sample Input

101 22 33 44 56 77 88 99 103 8

Sample Output

38

Hint

INPUT DETAILS: 
The set of connections in the input describes a "tree": it connects all the barns together and contains no cycles. 
OUTPUT DETAILS: 
If barn 3 or barn 8 is removed, then the remaining network will have one piece consisting of 5 barns and two pieces containing 2 barns. If any other barn is removed then at least one of the remaining pieces has size at least 6 (which is more than half of the original number of barns, 5).

Source

 
题意:和poj1655几乎是一样的。
 
 
1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 using namespace std; 9 10 vector
Q[10002];11 int num[10002];12 int dp[10002][2];13 bool use[10002];14 int Queue[10002],len;15 //dp[i][0] ×Ó½ÚµãµÄ×î´óÊýÁ¿16 //dp[i][1] ͳ¼Æ ×ӽڵ㼰×ÔÉí µÄ×ܸöÊý17 18 void add(int x,int y)19 {20 Q[x].push_back(y);21 num[x]++;22 }23 int Max(int x,int y)24 {25 return x>y? x:y;26 }27 void dfs(int k)28 {29 int i,t,cur=0;30 use[k]=true;31 dp[k][1]=1;32 for(i=0;i
0)48 {49 for(i=0;i<=n;i++)50 {51 Q[i].clear();52 num[i]=0;53 }54 memset(dp,0,sizeof(dp));55 memset(use,false,sizeof(use));56 57 for(i=1;i

 

转载于:https://www.cnblogs.com/tom987690183/p/3600352.html

你可能感兴趣的文章
Require的使用 CMD
查看>>
为什么软件定制项目难做?软件外包公司该怎么发展?
查看>>
官方揭秘OpenAI如何打败人类:10个月训练4.5万年
查看>>
一次前端面试经验总结
查看>>
POJ 2479 Maximum sum
查看>>
连线:微软Adobe同仇人忾 谋求配合抗衡苹果
查看>>
python中用os.system+sqlcmd执行sql脚本
查看>>
【PHP cookie | 欢迎效果】
查看>>
PB5.0 features/sysgen参数和ceconfig.h中宏定义的对应关系
查看>>
PHP与MySQL学习笔记8:重要概念与设计Web数据库
查看>>
11.22 访问日志不记录静态文件 11.23 访问日志切割 11.24 静态元素过期时间
查看>>
Bash脚本语法泛述
查看>>
SSH打通密钥后仍需要密码
查看>>
GZIP(1)
查看>>
在线压缩解压缩PHP代码
查看>>
使用vmware vdp备份2008虚机时,如果出错可以参考这篇文章。
查看>>
新网互联域名注册量动态:6月下旬净增3341个
查看>>
一台服务器的黑道生涯之六 保安来了
查看>>
LINUX的交换分区或交换文件SWAP的查看与维护
查看>>
Nacos 发布0.3.0版本,迄今为止最好看的版本
查看>>