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. [using_microsoft_infopath_2010]Chapter10 与SharePoint Designer工作流集成

    本章概要: 1.创建工作流集成表单 2.允许工作流手动触发 3.创建自定义动作按钮 4.使用人物设计器 5.维护工作流人物表单

  2. HDU 2817 EASY题

    #include <iostream> #include <cstdio> using namespace std; const __int64 MOD=200907; __i ...

  3. Web Service学习-CXF开发Web Service实例demo(一)

    Web Service是什么? Web Service不是框架.更甚至不是一种技术. 而是一种跨平台,跨语言的规范 Web Service解决什么问题: 为了解决不同平台,不同语言所编写的应用之间怎样 ...

  4. Android适屏

    总结一下自己的适屏经验,仅仅希望自己不断进步,不断完好,假设有热心肠的"前辈"指导一下,不胜感激! Android5.0已经出来了,说是这个版本号对Android屏幕适配做了非常多 ...

  5. Django -&gt; debug模式下的静态文件服务(/media/)

    正式公布django项目的时候,假设存在静态文件(通常会统一放在名称为media或static的文件夹下),则须要建立url到文件系统的映射,比如.使用nginx的时候我们须要进行这种配置. # Dj ...

  6. UVA 11728 - Alternate Task 数学

    Little Hasan loves to play number games with his friends. One day they were playing a game whereone ...

  7. C-结构体应用(10)

    结构体是用来定义多种类型的复合类型,在 C语言中与类的区别在于结构体注重的是数据而类除了数据还包含函数,第2点区别在于结构体所声明的成员默认是"public"点.而类的默认是pri ...

  8. TS4

    类: 类与对象字面量和接口差不多,比较两个类类型的对象时,只有实例的成员会被比较. 静态成员和构造函数不在比较的范围内. class Animal { feet: number; constructo ...

  9. 0x41 并查集

    太菜了才做到并查集啊啊啊啊啊啊啊啊啊啊啊 还是很有收获的说 水 bzoj4195: [Noi2015]程序自动分析 好题 poj1456 感受到并查集传递性的美妙啊!对于一个商品,去找他过期前那天的集 ...

  10. 使用CNN做电影评论的负面检测——本质上感觉和ngram或者LSTM同,因为CNN里图像检测卷积一般是3x3,而文本分类的话是直接是一维的3、4、5

    代码如下: from __future__ import division, print_function, absolute_import import tensorflow as tf impor ...