2015 多校联赛 ——HDU5325(DFS)
Crazy Bobo
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 1215 Accepted Submission(s): 366
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.
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.
3 30 350 100 200 300 400
1 2
2 3
3 4
4 5
5 6
6 7
题意:给一个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)的更多相关文章
- 2015 多校联赛 ——HDU5294(最短路,最小切割)
Tricks Device Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) To ...
- 2015 多校联赛 ——HDU5323(搜索)
Solve this interesting problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- 2015 多校联赛 ——HDU5305(搜索)
Friends Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Su ...
- 2015 多校联赛 ——HDU5299(树删边)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission ...
- 2015 多校联赛 ——HDU5416(异或)
CRB has a tree, whose vertices are labeled by 1, 2, …, N. They are connected by N – 1 edges. Each ed ...
- 2015 多校联赛 ——HDU5334(构造)
Virtual Participation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Ot ...
- 2015 多校联赛 ——HDU5302(构造)
Connect the Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- 2015 多校联赛 ——HDU5316(线段树)
Fantasy magicians usually gain their ability through one of three usual methods: possessing it as an ...
- 2015 多校联赛 ——HDU5319(模拟)
Painter Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Su ...
随机推荐
- 201621123050 《Java程序设计》第7周学习总结
1. 本周学习总结 1.1 思维导图:Java图形界面总结 2.书面作业 1. GUI中的事件处理 1.1 写出事件处理模型中最重要的几个关键词. 1.事件:用户的操作,例如点击或输入之类的操作 2. ...
- Twisted 延迟调用
延迟(defer)是twisted框架中实现异步的编程体系,使程序设计可以采用事件驱动的机制 1.基本使用 defer可以看作一个管理回调函数的对象,可以向该对象添加需要的回调函数同时也可以指定该组函 ...
- 【译】Gradle 的依赖关系处理不当,可能导致你编译异常
文章 | Ashesh Bharadwaj 翻译 | 承香墨影 授权 承香墨影 翻译.编辑并发布 在 Android Studio 中,Gradle 构建过程对于开发者来说,很大程度上是抽象的.作为一 ...
- Mysql-5.7.21安装配置
搞开发多年,其实MySql前前后后安装配置了无数次,但是每次都需要到网上搜教程,折腾半天才搞定,这次索性把整个过程全部记录下来,以便以后查阅. 下载 到MySql官网,导航找到DOWNLOADS> ...
- APP手机端加载不到资源服务器后台解决参考
今天发现app登录时,报could not get resource,日志中打印的是redis相关的错误,于是开始一步步检查错误! 后台架构:redis+mysql+elk+tomcat+zookee ...
- maven安装、配置
maven的安装和配置 1.将maven解压到自定义文件夹下.例如解压到如下目录(解压目录最好不要有中文字): 2:配置环境变量:一定要注意要用分号:与其他值隔开 3.在cmd中测试,验证是否安装成 ...
- javascript学习(4)异常处理 try-catch 和 onerror
一.try-catch 1.样例1 1.1.源代码 1.2.执行后 2.样例2 2.1.源代码 2.2.执行后 二.onerror 1.源代码 2.执行后
- ASP.NET CORE系列【三】使用Entity Framework Core进行增删改查
身份验证 以前我们熟悉的web.config中配置的form验证,现在没有了.我们来看看在Core里面如何配置: 首先需要NuGet安装一个包:Microsoft.AspNetCore.Authent ...
- Python中使用hashlib进行加密的简单使用
import hashlib ''' 原文= '字符串' 哈希加密对象 = hashlib.加密算法( 原文.encode('utf-8') ) 密文 = 哈希加密对象.hexdigest() #密文 ...
- wmv12下安装centos7
第一步:安装软件: vmw版本是12,并在vmw下安装centos为CentOS-7-x86_64-DVD-1708.iso: 第二步:修改vmw虚拟网络配置 1)配置VMnet8 修改ip等信息 点 ...