博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj3107 Godfather
阅读量:5249 次
发布时间:2019-06-14

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

Description

Last years Chicago was full of gangster fights and strange murders. The chief of the police got really tired of all these crimes, and decided to arrest the mafia leaders.

Unfortunately, the structure of Chicago mafia is rather complicated. There are n persons known to be related to mafia. The police have traced their activity for some time, and know that some of them are communicating with each other. Based on the data collected, the chief of the police suggests that the mafia hierarchy can be represented as a tree. The head of the mafia, Godfather, is the root of the tree, and if some person is represented by a node in the tree, its direct subordinates are represented by the children of that node. For the purpose of conspiracy the gangsters only communicate with their direct subordinates and their direct master.

Unfortunately, though the police know gangsters’ communications, they do not know who is a master in any pair of communicating persons. Thus they only have an undirected tree of communications, and do not know who Godfather is.

Based on the idea that Godfather wants to have the most possible control over mafia, the chief of the police has made a suggestion that Godfather is such a person that after deleting it from the communications tree the size of the largest remaining connected component is as small as possible. Help the police to find all potential Godfathers and they will arrest them.

Input

The first line of the input file contains n — the number of persons suspected to belong to mafia (2 ≤ n ≤ 50 000). Let them be numbered from 1 to n.

The following n − 1 lines contain two integer numbers each. The pair aibi means that the gangster ai has communicated with the gangster bi. It is guaranteed that the gangsters’ communications form a tree.

Output

Print the numbers of all persons that are suspected to be Godfather. The numbers must be printed in the increasing order, separated by spaces.

Sample Input

61 22 32 53 43 6

Sample Output

2 3 与相似
//Serene#include
#include
#include
#include
#include
#include
using namespace std;const int maxn=5e4+10;int T,n,tot;int aa;char cc;int read() { aa=0;cc=getchar(); while(cc<'0'||cc>'9') cc=getchar(); while(cc>='0'&&cc<='9') aa=aa*10+cc-'0',cc=getchar(); return aa;}int fir[maxn],nxt[2*maxn],to[2*maxn],e=0;void add(int x,int y) { to[++e]=y;nxt[e]=fir[x];fir[x]=e; to[++e]=x;nxt[e]=fir[y];fir[y]=e;}struct Node{ int pos,fa,size,maxnum;}node[maxn];void dfs(int pos) { node[pos].pos=pos; node[pos].size=1; for(int y=fir[pos];y;y=nxt[y]) { if(to[y]==node[pos].fa) continue; node[to[y]].fa=pos;dfs(to[y]); node[pos].maxnum=max(node[pos].maxnum,node[to[y]].size); node[pos].size+=node[to[y]].size; }}bool cmp(const Node& a,const Node& b) { int x=max(a.maxnum,tot-a.size),y=max(b.maxnum,tot-b.size); return x!=y? x

  

转载于:https://www.cnblogs.com/Serene-shixinyi/p/7482103.html

你可能感兴趣的文章
价值观
查看>>
mongodb命令----批量更改文档字段名
查看>>
CentOS 简单命令
查看>>
使用&nbsp;SharedPreferences 分类: Andro...
查看>>
TLA+(待续...)
查看>>
题解: [GXOI/GZOI2019]与或和
查看>>
MacOS copy图标shell脚本
查看>>
国外常见互联网盈利创新模式
查看>>
Oracle-05
查看>>
linux grep 搜索查找
查看>>
Not enough free disk space on disk '/boot'(转载)
查看>>
android 签名
查看>>
vue项目中使用百度统计
查看>>
android:scaleType属性
查看>>
SuperEPC
查看>>
mysql-5.7 innodb 的并行任务调度详解
查看>>
shell脚本
查看>>
Upload Image to .NET Core 2.1 API
查看>>
Js时间处理
查看>>
Java项目xml相关配置
查看>>