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 ...
随机推荐
- electron-vue工程创建
没有vue创建经验请移步至 vue下载与安装 使用vue创建electron-vue工程 vue init simulatedgreg/electron-vue my-project 安装elemen ...
- Welcome to Django!
Welcome to Django! 实验简介 Django是一个可以使Web开发工作更加高效愉快的Web开发框架.Django可以让你用最小的代价构建和维护更高质量的Web应用程序. 从好的方面来看 ...
- Linux 下的权限改变与目录配置
Linux 下的权限改变与目录配置 ./代表本目录的意思. (1):用户与用户组, 1:文件所有者,文件被某一用户所有 2:用户组: 对文件给与一个或者多个用户权限配置 3:其它人: (2):l ...
- typescript简介
微软作为编译器狂魔一直有一个心病,就是改良JavaScript这种语法超级烂又很多人用的编程语言,于是TypeScript诞生了 先做个对比吧: TS JS 语法严谨性 严谨 宽松 静态性 静态 ...
- 源码解析flask的路由系统
源码解析flask的路由系统 当我们新建一个flask项目时,pycharm通常已经为项目定义了一个基本路由 @app.route('/') def hello_world(): return 'He ...
- Docker学习笔记 - Docker的仓库
- zuul入门(4)zuul的注解@EnableZuulServer和@EnableZuulProxy
@EnableZuulServer.@EnableZuulProxy两个注解 @EnableZuulProxy简单理解为@EnableZuulServer的增强版,当Zuul与Eureka.Ribbo ...
- Spark入门(1-4)安装、运行Spark
如何安装Spark 安装和使用Spark有几种不同方式.你可以在自己的电脑上将Spark作为一个独立的框架安装或者从诸如Cloudera,HortonWorks或MapR之类的供应商处获取一个Spar ...
- C# Bootstrap table之 分页
效果如图: 一.声明talbe <div class="container"> <table id="table" class="t ...
- 关于阿里巴巴iconfont的使用方法
iconfont网址:http://www.iconfont.cn/ 说起iconfont,做前端开发的应该知道它的好处,图标库之丰富,只有你想不到的,没有你找不到的,而且轻量高清.用户在iconfo ...