Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int posx[10002];
- int nadyiet(int g, vector <int> graph[]){
- for(int k=0;k<graph[g].size();++k){
- posx[g]+= nadyiet(graph[g][k],graph)+1;
- }
- return ++posx[g];
- }
- int main(){
- int nCasos;
- int nodos;
- int a,b;
- cin >> nCasos;
- for(;;nCasos--){
- cin >> nodos;
- vector <int> node[nodos];
- for(int z=0;z<nodos-1;++z){
- cin >> a >> b;
- if(b>a){
- node[a].push_back(b);
- }
- else{
- node[b].push_back(a);
- }
- }
- a=nadyiet(0,node);
- for(int i=1;i<nodos;++i){
- posx[0]+=posx[i];
- posx[i]=0;
- }
- cout << posx[0] << endl;
- posx[0]=0;
- }
- }
Add Comment
Please, Sign In to add comment