Crazy Bobo

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 1334    Accepted Submission(s): 410

Problem Description
Bobo has a tree,whose vertices are conveniently labeled by 1,2,...,n.Each node has a weight wi. All the weights are distrinct.
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.
 
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.
 
Output
For each test output one line contains a integer,denoting the maximum size of Bobo Set.
 
Sample Input
7
3 30 350 100 200 300 400
1 2
2 3
3 4
4 5
5 6
6 7
 
Sample Output
5
 
Author
ZSTU
 
Source
 

解题:直接搜索。。。建立有向图时候,小权向大权的连边,然后看看每个每个点,最多能走多少个点。

 #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的更多相关文章

  1. hdu 5325 Crazy Bobo dfs

    // hdu 5325 Crazy Bobo // // 题目大意: // // 给你一棵树,树上每一个节点都有一个权值w,选择尽可能多的节点, // 这些节点相互联通,而且依照权值升序排序之后得到节 ...

  2. HDU 5325 Crazy Bobo(思路+dfs 记忆化)

    Crazy Bobo Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Tota ...

  3. hdu 5325 Crazy Bobo (树形dp)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Crazy Bobo Time Limit: 6000/3000 MS (Java ...

  4. DFS/BFS+思维 HDOJ 5325 Crazy Bobo

    题目传送门 /* 题意:给一个树,节点上有权值,问最多能找出多少个点满足在树上是连通的并且按照权值排序后相邻的点 在树上的路径权值都小于这两个点 DFS/BFS+思维:按照权值的大小,从小的到大的连有 ...

  5. 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 ...

  6. 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:  ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 加速 MySQL 导入导出的方法

    http://www.21andy.com/new/20100917/1952.html MySQL导出的SQL语句在导入时有可能会非常非常慢,在处理百万级数据的时候,可能导入要花几小时.在导出时合理 ...

  2. Elasticsearch 7.0 正式发布,盘他!

    Elastic{ON}北京分享了Elasticsearch7.0在Speed,Scale,Relevance等方面的很多新特性. 比快更快,有传说中的那么牛逼吗?盘他! 通过本文,你能了解到: Ela ...

  3. BA-闭式冷却塔系统

  4. gem update --system

    gem update --system 修改完gem sources之后,进行gem update: gem update --system 之后的输出: C:\Sites\test01>gem ...

  5. [React] How to use a setState Updater Function with a Reducer Pattern

    In this lesson we'll walk through setting up an updater function that can receive an action argument ...

  6. 结束QQ即时通信垄断,开辟即时通信互联互通instantnet时代

    结束QQ即时通信垄断,开辟即时通信互联互通instantnet时代 蓬勃发展的即时通信产业 即时通信(IM)是指可以即时发送和接收互联网消息等的业务. 即时通信.就是瞬间把信息发送给对方,假设不是即时 ...

  7. poj 2528 Mayor&#39;s posters 【线段树 + 离散化】

    Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 50643   Accepted: 14675 ...

  8. MongoDB 2.6安装

    Workaround to install as a service You can manually install 2.6.0 as a service on Windows from an Ad ...

  9. 2015.03.13,外语,读书笔记-《Word Power Made Easy》 10 “如何讨论交谈习惯”学习笔记 SESSION 26

    1.a Spartan virtue 古斯巴达人中一位有名的Laconia国王,其言语比Vermonter(美国佛蒙特州人)还简洁.一个传说,马其顿菲利普国王(亚历山大的老爸)要进攻他们的都城,发了一 ...

  10. 我的Android进阶之旅------&gt;android Button上面的英文字符串自己主动大写的问题解决

    今天碰到一个关于Button的问题:android Button上面的英文字符串会自己主动变成大写,执行的Android 5.1版本号,例如以下图所看到的: 图1:Button 图2:TextView ...