2015 Multi-University Training Contest 3 hdu 5325 Crazy Bobo
Crazy Bobo
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 1334 Accepted Submission(s): 410
A set with m nodes v1,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 get u1,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(excluding ui and ui+1),should satisfy wx<wui.
Your task is to find the maximum size of Bobo Set in a given tree.
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.
解题:直接搜索。。。建立有向图时候,小权向大权的连边,然后看看每个每个点,最多能走多少个点。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#pragma comment(linker, "/stack:1024000000,1024000000")
using namespace std;
const int maxn = ;
vector<int>g[maxn];
int w[maxn],ret[maxn];
void dfs(int u) {
ret[u] = ;
for(int i = g[u].size()-; i >= ; --i) {
if(!ret[g[u][i]]) dfs(g[u][i]);
ret[u] += ret[g[u][i]];
}
}
int main() {
int n,u,v;
while(~scanf("%d",&n)){
for(int i = ; i <= n; ++i){
scanf("%d",w+i);
g[i].clear();
}
for(int i = ; i < n; ++i){
scanf("%d%d",&u,&v);
if(w[u] < w[v]) g[u].push_back(v);
else g[v].push_back(u);
}
memset(ret,,sizeof ret);
int ans = ;
for(int i = ; i <= n; ++i){
if(!ret[i]) dfs(i);
ans = max(ans,ret[i]);
}
printf("%d\n",ans);
}
return ;
}
2015 Multi-University Training Contest 3 hdu 5325 Crazy Bobo的更多相关文章
- hdu 5325 Crazy Bobo dfs
// hdu 5325 Crazy Bobo // // 题目大意: // // 给你一棵树,树上每一个节点都有一个权值w,选择尽可能多的节点, // 这些节点相互联通,而且依照权值升序排序之后得到节 ...
- HDU 5325 Crazy Bobo(思路+dfs 记忆化)
Crazy Bobo Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Tota ...
- hdu 5325 Crazy Bobo (树形dp)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Crazy Bobo Time Limit: 6000/3000 MS (Java ...
- DFS/BFS+思维 HDOJ 5325 Crazy Bobo
题目传送门 /* 题意:给一个树,节点上有权值,问最多能找出多少个点满足在树上是连通的并且按照权值排序后相邻的点 在树上的路径权值都小于这两个点 DFS/BFS+思维:按照权值的大小,从小的到大的连有 ...
- 2015 Multi-University Training Contest 8 hdu 5390 tree
tree Time Limit: 8000ms Memory Limit: 262144KB This problem will be judged on HDU. Original ID: 5390 ...
- 2015 Multi-University Training Contest 8 hdu 5383 Yu-Gi-Oh!
Yu-Gi-Oh! Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: ...
- 2015 Multi-University Training Contest 8 hdu 5385 The path
The path Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: 5 ...
- 2015 Multi-University Training Contest 3 hdu 5324 Boring Class
Boring Class Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- 2015 Multi-University Training Contest 3 hdu 5317 RGCDQ
RGCDQ Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
随机推荐
- ZOJ 3885 The Exchange of Items
The Exchange of Items Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. O ...
- hdu 2491 贪心
#include<stdio.h> #include<stdlib.h> #define N 110000 struct node { int u,v,len,time; }m ...
- 关于C++构造函数一二
关于构造函数的调用顺序: 1.继承关系 2.从属关系 3.static声明的从属关系 关于拷贝构造函数的声明: classname(const classname & rhs) #includ ...
- [MFC]透明图展示
(Owed by: 春夜喜雨 http://blog.csdn.net/chunyexiyu 转载请标明来源) 一般我们可见的图形RGB三元色.对Alpha通道的话.它不一定会显示到窗口中来. 在Wi ...
- Android自己定义View之组合控件 ---- LED数字时钟
先上图 LEDView效果如图所看到的. 之前看到一篇博客使用两个TextView实现了该效果.于是我想用自己定义控件的方式实现一个LEDView.使用时就可以直接使用该控件. 採用组合控件的方式,将 ...
- 转:centos下升级git版本的操作记录
https://www.cnblogs.com/kevingrace/p/8252517.html 在使用git pull.git push.git clone的时候,或者在使用jenkins发版的时 ...
- [IOI 1999] 花店橱窗布置
[题目链接] https://www.luogu.org/problemnew/show/P1854v [算法] f[i][j]表示放了前i束花,第i束花放在第j个花瓶中,所能获得的最大美学值 由于要 ...
- nodejs免费空间
https://www.nitrous.io/join/N_aIGoSnOMI node免费空间,可以把自己node 代码部署到云端. 也可以在线编辑,当然也能在外网地址访问到,是自己学习nodejs ...
- 16. 3Sum Closest[M]最接近的三数之和
题目 Given an array nums of n integers and an integer target, find three integers in nums such that th ...
- 关于content-type
content-type 包含了表单类型和边界字符串信息. 关于content-type get请求的headers中没有content-type这个字段 post 的 content-type 有两 ...