fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5.  
  6. int main(){
  7. ios_base::sync_with_stdio(false);
  8. cin.tie(NULL);
  9. int n;
  10. cin>>n;
  11. vector<int>t[n+1];
  12. vector<int>v(n+1);
  13. for(int i=1;i<n;i++){
  14. int x,y;
  15. cin>>x>>y;
  16. t[x].push_back(y);
  17. t[y].push_back(x);
  18. }
  19. for(int i=1;i<=n;i++){
  20. if(t[i].size()==1){
  21. cout<<"Valid node is at index "<<i<<"\n";
  22. break;
  23. }
  24. }
  25. return 0;
  26. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty