Guest User

Untitled

a guest
Nov 25th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5.  
  6. int posx[10002];
  7.  
  8. int nadyiet(int g, vector <int> graph[]){
  9. for(int k=0;k<graph[g].size();++k){
  10. posx[g]+= nadyiet(graph[g][k],graph)+1;
  11. }
  12. return ++posx[g];
  13. }
  14.  
  15. int main(){
  16. int nCasos;
  17. int nodos;
  18. int a,b;
  19. cin >> nCasos;
  20. for(;;nCasos--){
  21. cin >> nodos;
  22. vector <int> node[nodos];
  23. for(int z=0;z<nodos-1;++z){
  24. cin >> a >> b;
  25. if(b>a){
  26. node[a].push_back(b);
  27. }
  28. else{
  29. node[b].push_back(a);
  30. }
  31. }
  32. a=nadyiet(0,node);
  33. for(int i=1;i<nodos;++i){
  34. posx[0]+=posx[i];
  35. posx[i]=0;
  36. }
  37. cout << posx[0] << endl;
  38. posx[0]=0;
  39. }
  40. }
Add Comment
Please, Sign In to add comment