标签:ios 博客 led tracking bigger rac stack not title
7 3 30 350 100 200 300 400 1 2 2 3 3 4 4 5 5 6 6 7
5
/*
參考此人博客 :http://www.mamicode.com/info-detail-948802.html
记得用c++交
*/
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
using namespace std;
#define N 800005
vector<int>g[N];
int n;
int ans[N];
int a[N];
int dfs(int u)
{
if(ans[u]) return ans[u];
ans[u]=1;
for(int i=0;i<g[u].size();i++)
{
int to=g[u][i];
ans[u]+=dfs(to);
}
return ans[u];
}
int main()
{
int i,j;
while(~scanf("%d",&n))
{
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(i=1;i<=n;i++)
g[i].clear();
memset(ans,0,sizeof(ans));
int u,v;
i=n-1;
while(i--)
{
scanf("%d%d",&u,&v);
if(a[u]<a[v]) g[u].push_back(v);
else g[v].push_back(u);
}
int temp=0;
for(i=1;i<=n;i++)
{
temp=max(temp,dfs(i));
}
printf("%d\n",temp);
}
return 0;
}
HDU 5325 Crazy Bobo(思路+dfs 记忆化)
标签:ios 博客 led tracking bigger rac stack not title
原文地址:http://www.cnblogs.com/wzzkaifa/p/6940097.html