func_code_string: #include <bits/stdc++.h>   using namespace std;   const int nMax = 100007;   int parent[nMax];   vector<int> g[nMax];   bool used[nMax];   void dfs(int root, int parent, int& cnt, int b, bool& bad) {     if (root == b) {       bad = true;     }     used[root] = true;     ++cnt;     for (int i = 0; i < g[root].size(); ++i) {       int to = g[root][i];       if (used[to] == false && to != parent) dfs(to, root, cnt, b, bad);     }   }   int main() {     int n, pos;     scanf( %d%d , &n, &pos);     for (int i = 0; i < n; ++i) {       int a;       scanf( %d , &a);       parent[i] = a - 1;       if (a != 0) {         g[i].push_back(a - 1);         g[a - 1].push_back(i);       }     }     --pos;     int h = 1;     int t = pos;     while (parent[t] != -1) {       ++h;       t = parent[t];     }     vector<int> c;     for (int i = 0; i < n; ++i) {       int cnt = 0;       bool bad = false;       if (used[i] == false) {         dfs(i, -1, cnt, pos, bad);         if (!bad) c.push_back(cnt);       }     }     int to = (int)pow(2.0, (int)c.size());     set<int> s;     set<int>::iterator it;     for (int i = 1; i < to + 1; ++i) {       int t = i, sum = 0;       for (int j = 0; j < c.size(); ++j) {         if (t & 1) sum += c[j];         t >>= 1;       }       s.insert(sum);     }     set<int> ans;     ans.insert(h);     for (it = s.begin(); it != s.end(); ++it) ans.insert(*it + h);     for (it = ans.begin(); it != ans.end(); ++it) cout << *it << endl;     return 0;   }   