Crazy Bobo

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

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
 
Source

题意:给一个n,然后给n个点的值,再输入n-1条边,构成一个树(当时没看懂要求啥 QAQ)后来看别人的解题报告大致明白,

3    30    350    100    200    300    400    可以建成以下有向图

1 -->2-->3<--4-->5-->6-->7     当在点4的时候,能总共走过5个点,所以输出5(感觉不难  - -!!  论英语的重要性)

用深搜要手动扩栈,C++提交,否则会出现  Runtime Error  (ACCESS_VIOLATION)   //表示新手并不知道这是啥

当时就是因为提交出了这个,以为这题自己想得太简单,就放弃了 - -

而且官方给的测试数据,正确代码也只能输出一半,搞得一直以为自己错了!!

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")//手动扩栈
typedef long long ll;
using namespace std;
const int maxn= 5e5 + 5;
const ll INF = 1000000000000000000;
int p[maxn];
vector<int>q[maxn];
int num[maxn]; void dfs(int u)
{
num[u]++;
int len = q[u].size();
for(int i = 0;i < len;i++)
{
int son = q[u][i];
if(!num[son])
dfs(son);
num[u]+=num[son];
}
} int main()
{
int n;
//freopen("10.txt","r",stdin);
while(scanf("%d",&n) != EOF)
{
for(int i = 1;i <= n;i++)
scanf("%d",&p[i]); int a,b;
for(int i = 1;i <= n;i++)
q[i].clear();
for(int i = 1;i < n;i++)
{
scanf("%d%d",&a,&b);
if(p[a] < p[b])
q[a].push_back(b);
else
q[b].push_back(a);
}
int ans = 0;
memset(num,0,sizeof(num));
for(int i = 1;i <= n;i++)
{
if(!num[i])
dfs(i);
ans= max(ans,num[i]);
} printf("%d\n",ans);
}
}

  

2015 多校联赛 ——HDU5325(DFS)的更多相关文章

  1. 2015 多校联赛 ——HDU5294(最短路,最小切割)

    Tricks Device Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

  2. 2015 多校联赛 ——HDU5323(搜索)

    Solve this interesting problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  3. 2015 多校联赛 ——HDU5305(搜索)

    Friends Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Su ...

  4. 2015 多校联赛 ——HDU5299(树删边)

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission ...

  5. 2015 多校联赛 ——HDU5416(异或)

    CRB has a tree, whose vertices are labeled by 1, 2, …, N. They are connected by N – 1 edges. Each ed ...

  6. 2015 多校联赛 ——HDU5334(构造)

    Virtual Participation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Ot ...

  7. 2015 多校联赛 ——HDU5302(构造)

    Connect the Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  8. 2015 多校联赛 ——HDU5316(线段树)

    Fantasy magicians usually gain their ability through one of three usual methods: possessing it as an ...

  9. 2015 多校联赛 ——HDU5319(模拟)

    Painter Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Su ...

随机推荐

  1. WPF自学入门(十)WPF MVVM简单介绍

     前面文章中,我们已经知道,WPF技术的主要特点是数据驱动UI,所以在使用WPF技术开发的过程中是以数据为核心的,WPF提供了数据绑定机制,当数据发生变化时,WPF会自动发出通知去更新UI. 我们不管 ...

  2. 【作业】HansBug的前三次OO作业分析与小结

    OO课程目前已经进行了三次的作业,容我在本文中做一点微小的工作. 第一次作业 第一次作业由于难度不大,所以笔者程序实际上写的也比较随意一些.(点击就送指导书~) 类图 程序的大致结构如下: 代码分析 ...

  3. 服务器磁盘阵列数据恢复,raid5两块硬盘掉线数据恢复方法

    [用户单位信息] 农业科学研究院某研究所 [磁盘阵列故障发生过程描述]客户的DELL MD1000服务器内置15块1TB硬盘搭建为RAID5磁盘阵列阵列,服务器在正常工作中有一块硬盘离线,管理员对磁盘 ...

  4. 原始的Ajax方法 (异步的 JavaScript 和 XML -- (Extensible Markup Language 可扩展标记语言))

    <script language="javascript" type="text/javascript"> var request = false; ...

  5. 关于PHP7

    目前一直使用php7也看了许多文档视频等,整理一下相关细节(仅为记录-),对于PHP7性能,如下图所示. * 在wordpress3.0.1中 php7比php5.6性能提升约3倍左右 新特性 一.变 ...

  6. python全栈开发-常用模块的一些应用

    一.random模块详解 1.概述 首先我们看到这个单词是随机的意思,他在python中的主要用于一些随机数,或者需要写一些随机数的代码,下面我们就来整理他的一些用法 2.常用方法 1. random ...

  7. C语言学习(二)

    今天在程序员面试题中,碰到一个有意思的题目:数组a[N],存放了1至N-1个数,其中某个数重复一次,现在要求找出重复的数字且程序时间复杂度必须为O(N).乍一看,如果不计时间复杂度和空间复杂度程序比较 ...

  8. 【漏洞复现】PHPCMS wap模块 SQL注入(附EXP)

    漏洞影响版本:v9.5.8.v9.6.0 Step1: 访问:http://www.xxx.com/index.php?m=wap&a=index&siteid=1, 获取返回的coo ...

  9. 新概念英语(1-97)A Small Blue Case

    Lesson 97 A small blue case 一只蓝色的小箱子 Listen to the tape then answer this question. Does Mr. Hall get ...

  10. Android WebView那些坑之上传文件

    最近公司项目需要在WebView上调用手机系统相册来上传图片,开发过程中发现在很多机器上无法正常唤起系统相册来选择图片. 解决问题之前我们先来说说WebView上传文件的逻辑:当我们在Web页面上点击 ...