比赛 |
20160415x |
评测结果 |
WEEEEEEEWE |
题目名称 |
游戏内测 |
最终得分 |
0 |
用户昵称 |
WAHT |
运行时间 |
1.811 s |
代码语言 |
C++ |
内存使用 |
13.67 MiB |
提交时间 |
2016-04-15 16:22:55 |
显示代码纯文本
- #include<iostream>
- #include<cstring>
- #include<cstdio>
- #include<algorithm>
- #include<cmath>
- #define ll long long
- using namespace std;
- const int maxn=500010;
- ll a[maxn];
- int n;
- struct my
- {
- int next,y;
- }e[maxn*2];
- int linkk[maxn],len;
- ll ans;
- void insert(int xx,int yy)
- {
- e[++len].next=linkk[xx],linkk[xx]=len;
- e[len].y=yy;
- }
- void dfs(int x,int fa,int dis)
- {
- ans=max(ans,dis+a[x]);
- for(int i=linkk[x];i;i=e[i].next)
- {
- int to=e[i].y;
- if(to==fa) continue;
- dfs(x,to,dis+1);
- }
- }
- int main()
- {
- freopen("gamebeta.in","r",stdin);
- freopen("gamebeta.out","w",stdout);
- cin>>n;
- for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
- for(int i=1;i<n;i++)
- {
- int a,b;
- scanf("%d%d",&a,&b);
- insert(a,b);
- insert(b,a);
- }
- ans=1LL*2*(n-1)+a[1];
- dfs(1,0,0);
- cout<<ans<<endl;
- return 0;
- }