2015 多校联赛 ——HDU5325(DFS)
来源:互联网 发布:12寸windows平板 编辑:程序博客网 时间:2024/05/18 02:23
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 nodesv1,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 getu1,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.
A set with m nodes
- 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
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.
The first line contains a integer 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
73 30 350 100 200 300 4001 22 33 44 55 66 7
Sample Output
5
Source
2015 Multi-University Training Contest 3
题意:给一个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); }}
0 0
- 2015 多校联赛 ——HDU5325(DFS)
- hdu5325(2015多校3)--Crazy Bobo(dfs)
- 2015 多校联赛 ——HDU5289(二分+ST)
- 2015多校联赛 ——HDU5288(数学)
- 2015 多校联赛 ——HDU5299(树删边)
- 2015 多校联赛 ——HDU5305(搜索)
- 2015 多校联赛 ——HDU5303(贪心)
- 2015 多校联赛 ——HDU5301(技巧)
- 2015 多校联赛 ——HDU5319(模拟)
- 2015 多校联赛 ——HDU5323(搜索)
- 2015 多校联赛 ——HDU5316(线段树)
- 2015 多校联赛 ——HDU5302(构造)
- 2015 多校联赛 ——HDU5335(Walk out)
- 2015 多校联赛 ——HDU5334(构造)
- 2015 多校联赛 ——HDU5344(水)
- 2015 多校联赛 ——HDU5349(水)
- 2015 多校联赛 ——HDU5350(huffman)
- 2015 多校联赛 ——HDU5348(搜索)
- Android功能自动化之MokeyRunner
- 强连通分量(kosaraju)
- 自动释放池autoreleasepool
- 黑马程序员——JAVA基础------反射
- 莫比乌斯反演
- 2015 多校联赛 ——HDU5325(DFS)
- Android基础_数据存储二_SharedPreferences存储
- Java 内部类实现原理简单分析
- HDU 2829 Lawrence (斜率优化DP)
- linux shell 判断文件是否存在等符号
- MIPS 指令
- UVALive 6800 The Mountain of Gold (bellman_ford判负环)
- 【Android应用开发技术:应用组件】Fragment使用方法
- URI规范的百分比编码