hdu5325记忆化深搜
来源:互联网 发布:在vb中cstr是什么意思 编辑:程序博客网 时间:2024/05/16 12:34
Crazy Bobo
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 2068 Accepted Submission(s): 737
Problem Description
Bobo has a tree,whose vertices are conveniently labeled by 1,2,...,n.Each node has a weightwi . All the weights are distrinct.
A set with m nodesv1,v2,...,vm is a Bobo Set if:
- The subgraph of his tree induced by this set is connected.
- After we sort these nodes in set by their weights in ascending order,we getu1,u2,...,um ,(that is,wui<wui+1 for i from 1 to m-1).For any node x in the path from ui to ui+1 (excludingui and ui+1 ),should satisfy wx<wui .
Your task is to find the maximum size of Bobo Set in a given tree.
A set with m nodes
- The subgraph of his tree induced by this set is connected.
- After we sort these nodes in set by their weights in ascending order,we get
Your task is to find the maximum size of Bobo Set in a given tree.
Input
The input consists of several tests. For each tests:
The first line contains a integer n (1≤n≤500000 ). Then following a line contains n integers w1,w2,...,wn (1≤wi≤109 ,all the wi is distrinct).Each of the following n-1 lines contain 2 integers ai and bi ,denoting an edge between vertices ai and bi (1≤ai,bi≤n ).
The sum of n is not bigger than 800000.
The first line contains a integer n (
The sum of n is not bigger than 800000.
Output
For each test output one line contains a integer,denoting the maximum size of Bobo Set.
Sample Input
73 30 350 100 200 300 4001 22 33 44 55 66 7
Sample Output
5
Author
ZSTU
Source
2015 Multi-University Training Contest 3
#include<cstdio>#include<iostream>#include<vector>#include<string>#include<string.h>#include<algorithm> #pragma comment(linker,"/STACK:1024000000,1024000000") using namespace std;const int MAXN=500010;int v[MAXN];int n;vector<int> e[MAXN];int num[MAXN];int ans;int h;int dfs(int fa){if(num[fa]) return num[fa];num[fa]=1;for(int i=0;i<e[fa].size();i++){int son=e[fa][i];num[fa]+=dfs(son);ans=max(ans,num[fa]);}return num[fa];}int main(){while(scanf("%d",&n)!=EOF){for(int i=1;i<=n;i++)scanf("%d",&v[i]);int a,b;for(int i=0;i<n-1;i++){scanf("%d%d",&a,&b);if(v[a]<v[b]){e[a].push_back(b);} else{e[b].push_back(a);}}ans=1;memset(num,0,sizeof(num));for(h=1;h<=n;h++)dfs(h);printf("%d\n",ans);for(int i=1;i<=n;i++)e[i].clear();}}
阅读全文
0 0
- hdu5325记忆化深搜
- hdu5325 Crazy Bobo
- hdu5325(排序+dp)
- hdu5325 Crazy Bobo
- hdu5325 树的思维题
- hdu5325 多校第三场1010
- hdu5325 找树中的最大集合
- 解题报告 之 HDU5325 Crazy Bobo
- hdu5325 Crazy Bobo(建图,搜索)
- 记忆化深搜+dp
- skiing-记忆化深搜
- hdu 1342 记忆化深搜
- 记忆化深搜模板
- 记忆
- 记忆
- 记忆
- 记忆
- 记忆
- 【Android Fragment】DialogFragment怎么玩?
- 异步转接标签
- centos7下ldap服务搭建
- 关于javascript的一些知识点
- 入门北京linux嵌入式培训行吗
- hdu5325记忆化深搜
- CS模式聊天软件
- Day4-11.Your first Java program
- 概率+逆元 书
- API对接网关 code review
- Couldn't save uncommitted changes. Tried to save uncommitted changes in stash before Update...
- Android AbsListView.OnScrollListener
- 幂等
- hadoop容器化