Advertisement
Kevin_Zhang

Untitled

Oct 20th, 2020
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define pb emplace_back
  3. #define AI(i) begin(i), end(i)
  4. using namespace std;
  5. using ll = long long;
  6. #ifdef KEV
  7. #define DE(args...) kout("[ " + string(#args) + " ] = ", args)
  8. void debug(auto L, auto R) { while (L < R) cerr << *L << " \n"[L+1==R], ++L; }
  9. void kout(){ cerr << endl; }
  10. template<class T1, class ...T2> void kout(T1 a, T2 ...e) { cerr << a << ' ', kout(e...); }
  11. #else
  12. #define DE(...) 0
  13. #define deubg(...) 0
  14. #endif
  15. const int MAX_N = 300010;
  16. vector<int> edge[MAX_N];
  17. int n;
  18. void dfs(int x, int lst = -1) {
  19.     for (int u : edge[x])
  20.         if (u != lst)
  21.             dfs(u, x);
  22. }
  23. signed main(){
  24.     ios_base::sync_with_stdio(0), cin.tie(0);
  25.     cin >> n;
  26.     for (int i = 1, a, b;i < n;++i) {
  27.         cin >> a >> b;
  28.         edge[a].pb(b); 
  29.         edge[b].pb(a);
  30.     }
  31.     dfs(1);
  32. }
  33.  
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement