func_code_string: #include <bits/stdc++.h>   using namespace std;   class Node {     set<int> adj;       public:     bool isLeave() const { return adj.size() == 1; }     void add(int v) { adj.insert(v); }     void remove(int v) { adj.erase(v); }     int front() const { return *adj.begin(); }   };   const int N = 100001;   Node neighbors[N];   bool marked[N] = {};   int level[N] = {};   int pred[N] = {};   list<int>::iterator sortedPos[N];   int main() {     int n;     cin >> n;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       neighbors[u].add(v);       neighbors[v].add(u);     }     cout << 1;     if (n == 1) {       cout << endl;     } else if (n == 2) {       cout <<     << 2 << endl;     } else {       list<int> leaves, sorted;       for (int i = 1; i <= n; i++) {         if (neighbors[i].isLeave()) leaves.push_back(i);         sortedPos[i] = sorted.end();       }       {         while (!leaves.empty()) {           const int u = leaves.front();           leaves.pop_front();           if (neighbors[u].isLeave()) {             const int v = neighbors[u].front();             if (level[u] + 1 > level[v]) {               level[v] = level[u] + 1;               pred[v] = u;               if (sortedPos[v] != sorted.end()) sorted.erase(sortedPos[v]);               assert(sorted.empty() || level[v] >= level[sorted.front()]);               sorted.push_front(v);               sortedPos[v] = sorted.begin();             }             neighbors[u].remove(v);             neighbors[v].remove(u);             if (neighbors[v].isLeave()) leaves.push_back(v);           }         }         int k = 2;         int controlled = 0;         int v = sorted.front();         sorted.pop_front();         controlled += level[v] + 1;         assert(!marked[v]);         marked[v] = true;         v = pred[v];         while (v) {           assert(!marked[v]);           marked[v] = true;           v = pred[v];         }         while (!sorted.empty() && controlled < n - 1) {           v = sorted.front();           sorted.pop_front();           if (!marked[v]) {             controlled += level[v] + 1;             marked[v] = true;             v = pred[v];             while (v) {               assert(!marked[v]);               marked[v] = true;               v = pred[v];             }             cout <<     << controlled;             k++;           }         }         for (; k <= n; k++) {           if (controlled < n) controlled++;           cout <<     << controlled;         }         cout << endl;       }     }     return 0;   }   