fork download
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5. typedef vector<ll> vint;
  6. typedef string st;
  7. typedef map<int,int> mii;
  8. typedef pair<int,int> pii;
  9.  
  10. #define pb push_back
  11. #define int long long
  12. #define vsrt(v) sort(v.begin(), v.end())
  13. #define all(v) v.begin(),v.end()
  14. #define scan(v, n) rep(i, 0, n) { cin>>v[i]; }
  15. #define print(v) for (auto x : v) { cout << x sp; } cout << endl;
  16. #define show(m) lp(m) cout<<x.F<<sp<<x.S<<endl;
  17. #define rep(i, j, k) for (long long i = j; i < k; i++)
  18. #define lp(m) for(auto &x:m)
  19. #define ascending [](const pair<int,int>&a, const pair<int,int>&b){return a.first<b.first;}
  20. #define in ll n; cin>>n;
  21. #define vin in; vint v(n); scan(v,n);
  22. #define cs st s; cin>>s;
  23. #define endl <<'\n'
  24. #define sp <<" "
  25. #define yes {cout << "YES" endl; return;}
  26. #define no {cout << "NO" endl; return;}
  27. #define ans(s) cout << s endl
  28. #define F first
  29. #define S second
  30. #define mod 1000000007
  31. #define off false
  32. #define on true
  33. #define baire string::npos
  34.  
  35. const int N = 2e5+1;
  36.  
  37. void fast(void) {
  38. ios_base::sync_with_stdio(false);
  39. cin.tie(nullptr);
  40. cout.tie(nullptr);
  41. }
  42.  
  43. void solve() {
  44. int n;
  45. cin>>n;
  46. int dp[n+1];
  47. bool vis[n+1];
  48. memset(vis,0,sizeof(vis));
  49. vector<vint> g(N+1);
  50. memset(dp,-1,sizeof(dp));
  51. rep(i,0,n-1){
  52. int x,y;
  53. cin>>x>>y;
  54. g[x].pb(y);
  55. g[y].pb(x);
  56. }
  57. auto dfs = [&](auto&& self, int u) -> void {
  58. vis[u] = on;
  59. cout << u << " ";
  60. for (auto &x : g[u]) {
  61. if (vis[x]) continue;
  62. self(self, x);
  63. }
  64. };
  65.  
  66. dfs(dfs, 1);
  67. }
  68.  
  69. int32_t main() {
  70. fast();
  71. int TC(1);
  72. cin >> TC;
  73. while (TC--) solve();
  74. }
Runtime error #stdin #stdout 0.02s 12164KB
stdin
Standard input is empty
stdout
Standard output is empty