fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define faster ios_base::sync_with_stdio(false); cin.tie(NULL)
  4. #define Bit(mask , i) ((mask >> i) & 1)
  5. #define fi first
  6. #define se second
  7. #define _LOG2(nl) 31 - __builtin_clz(nl)
  8. #define c_bit(nl) __builtin_popcount(nl)
  9. #define li pair<long long , int>
  10. #define db double
  11. #define onBit(mask , i) (mask | (1 << i))
  12. #define offBit(mask , i) (mask & (~(1 << i)))
  13.  
  14. const long long MOD = 1e9 + 9;
  15. const long long INF = 1e14;
  16. const int N = 1e5 + 7;
  17. int C , n , k , res;
  18. vector<int> a[N];
  19. int h[N];
  20.  
  21. void inp(){
  22. cin >> C >> n >> k;
  23. for (int i = 1 ; i < n ; ++i){
  24. int u , v;
  25. cin >> u >> v;
  26. a[u].push_back(v);
  27. a[v].push_back(u);
  28. }
  29. }
  30.  
  31. void bfs(){
  32. queue<int> q;
  33. q.push(1);
  34. h[1] = 1;
  35. int cnt = 0;
  36. while (q.size()){
  37. int u = q.front();
  38. q.pop();
  39.  
  40. for (int v : a[u]) if (!h[v]){
  41. h[v] = h[u] + 1;
  42. ++cnt;
  43. if (cnt == k){
  44. res = h[v];
  45. }
  46. q.push(v);
  47. }
  48. }
  49. }
  50.  
  51. void solve(){
  52. bfs();
  53. for (int i = 1 ; i <= n ; ++i) if (h[i] == res)
  54. cout << i << " ";
  55. }
  56.  
  57. int main(){
  58. // freopen("xhmax.inp" , "r" , stdin);
  59. // freopen("xhmax.out" , "w" , stdout);
  60. faster;
  61. inp();
  62. solve();
  63. return 0;
  64. }
  65.  
Success #stdin #stdout 0.01s 5876KB
stdin
Standard input is empty
stdout
Standard output is empty