Advertisement
Guest User

Uj

a guest
Feb 20th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. ifstream in("mere.in");
  4. ofstream out("mere.out");
  5. int a[1001][1001],n,v[1001],c[1001],x,y,sum;
  6. inline void dfs(int r)
  7. {
  8. register int maxx=0,crt=0;
  9. sum+=v[r],c[r]=1;
  10. for(int i=1;i<=n;i++)
  11. if(!c[i] && a[r][i])
  12. {
  13. c[i]=1;
  14. if(v[i]>maxx)
  15. maxx=v[i],crt=i;
  16. }
  17. if(crt)
  18. dfs(crt);
  19. }
  20. inline void citire()
  21. {
  22. in>>n;
  23. for(int i=1;i<=n;i++)
  24. in>>v[i];
  25. while(in>>x>>y)
  26. a[x][y]=a[y][x]=1;
  27. dfs(1);
  28. out<<sum;
  29. }
  30. int main()
  31. {
  32. citire();
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement