POJ 3107 Godfather 树状DP
来源:互联网 发布:tensorflow mnist例子 编辑:程序博客网 时间:2024/05/17 04:45
这题其实就是一个简单的树状DP,但是最扯的是它居然要卡STL,超时超到哭啊,只能用链表了。
#include <cstdio>#include <cstring>#include <string>#include <iostream>#include <queue>#include <algorithm>#include <map>#include <vector>#include <cmath>#include <stack>using namespace std;#define ll long long#define int64 __int64#define M 100005#define N 1005#define inf 1000010#define mod 1000000007struct node{int sum_son;int max_son;int pos;}tp[M];struct Node{int ev , next;}tree[M];int n , head[M] , tot;void Addedge(int s , int e){tree[tot].ev = e;tree[tot].next = head[s];head[s] = tot++;}void Dfs(int s , int fa){tp[s].max_son = 0;tp[s].sum_son = 1;tp[s].pos = s;int i;for (i = head[s] ; i != -1 ; i = tree[i].next){int v = tree[i].ev;if (v == fa)continue;Dfs(v,s);tp[s].max_son = max(tp[s].max_son , tp[v].sum_son);tp[s].sum_son += tp[v].sum_son;}tp[s].max_son = max(tp[s].max_son , n-tp[s].sum_son);}bool cmp(node a , node b){if (a.max_son < b.max_son)return true;if (a.max_son > b.max_son)return false;if (a.pos < b.pos)return true;return false;}int main(){while (~scanf("%d",&n)){int i;tot = 0;memset(head , -1 , sizeof head);for (i = 1 ; i < n ; i++){int s , e;scanf("%d%d",&s,&e);Addedge(s,e);Addedge(e,s);}Dfs(1,0);sort(tp+1 , tp+n+1 , cmp);printf("%d",tp[1].pos);i = 2;while (i <= n && tp[i].max_son == tp[1].max_son)printf(" %d",tp[i++].pos);printf("\n");}return 0;}
- POJ 3107 Godfather 树状DP
- POJ 3107 Godfather(树形dp)
- Godfather - POJ 3107 树形dp
- POJ 3107 Godfather (树形DP)
- poj 3107 Godfather (树形dp)
- 【POJ】3107 Godfather 树形dp
- POJ 3107 - Godfather 树形DP..vector慎用...
- poj 3107 Godfather(树形dp)
- (简单) 树形dp POJ 3107 Godfather
- POJ 3107 Godfather (水题,树形DP)
- POJ 3107 Godfather(树形DP)
- POJ 3107 Godfather(树形DP)
- poj 3107 Godfather(树形DP)
- poj 3107 Godfather(树形dp)
- poj 3170 Godfather(树形dp)
- poj 3107 Godfather(树形dp,树的重心)
- (POJ 3107 Godfather)树型DP + 删点
- POJ.3107 Godfather (树形DP 树的重心)
- 命令创建oracle表空间和用户
- vs2010语法检查的红线问题
- 勿以专家自居
- 动画-IOS开发
- POJ 1080 Human Gene Functions
- POJ 3107 Godfather 树状DP
- JAVA打蜜蜂小游戏源码
- 穷人最缺少的是什么
- iOS块语法详解(block编程)
- Swing事件分发线程EDT与SwingUtilities.invokeLater
- 错误:Only the original thread that created a view hierarchy can touch its views——Handler的使用
- Spring 教程 - Spring AOP 详解
- 关于一道简单的Java 基础面试题的剖析: short s1=1;s1 = s1 +1会报错吗?
- FLEX SharedObject介绍及应用