poj 1655 DP
来源:互联网 发布:trados翻译软件官方 编辑:程序博客网 时间:2024/06/15 09:35
#include<cstdio>#include<cstring>#define MAX(x,y) ((x)>(y)?(x):(y))struct node{int to,next;}e[41000];int cnt,head[21000],n;void add_edge(int from,int to){ e[cnt].to=to;e[cnt].next=head[from];head[from]=cnt++;}int dp[20010];int num[20010];void dfs(int u,int v){dp[u]=1;for(int i=head[u];i!=-1;i=e[i].next){int to=e[i].to;if(to==v)continue;dfs(to,u);dp[u]+=dp[to];num[u]=MAX(num[u],dp[to]);}}int main(){int T;scanf("%d",&T);while(T--){scanf("%d",&n);cnt=0;memset(head,-1,sizeof(head));for(int i=1;i<n;i++){int a,b;scanf("%d%d",&a,&b);add_edge(a,b);add_edge(b,a);}memset(num,0,sizeof(num)); dfs(1,-1); int res=0x3f3f3f3f,lo;for(int i=1;i<=n;i++){if(res>MAX(n-dp[i],num[i])){lo=i;res=MAX(n-dp[i],num[i]);}}printf("%d %d\n",lo,res);}}
阅读全文
0 0
- poj 1655 树型DP
- poj 1655 树状dp
- poj 1655 树形DP
- poj 1655 树形dp
- poj 1655(树形dp)
- POJ-1655-树形dp
- poj 1655 DP
- poj 1655树形dp && poj 3107 &&poj 2378 && poj 3140
- poj 1655 简单树形dp
- POJ 1655 简单树形dp
- poj dp
- 【dp】POJ
- 【dp】POJ
- [DP] POJ
- [DP] POJ
- [DP] POJ
- 【dp】POJ
- POJ 1655 Balancing Act 树形dp
- 欧几里德的游戏
- 【算法】程序猿不写代码是不对的58
- vs2010连接mysql数据库(含win32和x64两种平台)
- Help Hanzo (数论(素数(打表进阶(任意段区域打表)))))
- Linux(八)用户管理
- poj 1655 DP
- CUDA学习笔记一
- Redis protected-mode
- java多线程什么时候释放锁—wait()、notify()
- 拆分·数字
- Jmeter图形监控扩展安装
- Delphi 的 Toolbar 的添加图片说明
- NYOJ-306走迷宫(二分查找+DFS)
- TCP/IP详解卷一学习笔记之一——Introduction