比赛 20160415x 评测结果 WEEEEEEEWE
题目名称 游戏内测 最终得分 0
用户昵称 WAHT 运行时间 1.811 s
代码语言 C++ 内存使用 13.67 MiB
提交时间 2016-04-15 16:22:55
显示代码纯文本
  1. #include<iostream>
  2. #include<cstring>
  3. #include<cstdio>
  4. #include<algorithm>
  5. #include<cmath>
  6. #define ll long long
  7. using namespace std;
  8. const int maxn=500010;
  9. ll a[maxn];
  10. int n;
  11. struct my
  12. {
  13. int next,y;
  14. }e[maxn*2];
  15. int linkk[maxn],len;
  16. ll ans;
  17. void insert(int xx,int yy)
  18. {
  19. e[++len].next=linkk[xx],linkk[xx]=len;
  20. e[len].y=yy;
  21. }
  22. void dfs(int x,int fa,int dis)
  23. {
  24. ans=max(ans,dis+a[x]);
  25. for(int i=linkk[x];i;i=e[i].next)
  26. {
  27. int to=e[i].y;
  28. if(to==fa) continue;
  29. dfs(x,to,dis+1);
  30. }
  31. }
  32. int main()
  33. {
  34. freopen("gamebeta.in","r",stdin);
  35. freopen("gamebeta.out","w",stdout);
  36. cin>>n;
  37. for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
  38. for(int i=1;i<n;i++)
  39. {
  40. int a,b;
  41. scanf("%d%d",&a,&b);
  42. insert(a,b);
  43. insert(b,a);
  44. }
  45. ans=1LL*2*(n-1)+a[1];
  46. dfs(1,0,0);
  47. cout<<ans<<endl;
  48. return 0;
  49. }