Language: C++

    st[dep[x]].push_back(x);
    for (int p=now[x];p;p=pre[p])
	{
	    int child=son[p];
	    fa[child]=x;dep[child]=dep[x]+1;
	    dfs(child);
	}
}

void solve(int x)
{
    for (int i=1;i<=k;i++)
	{
	    if (vis[x]) return;
	    vis[x]=1;
	    x=fa[x];
	}
    ans+=(x!=1);
}

int main()
{
    n=read(),k=read();
    int x=read();if (x!=1) ans=1;
    for (int i=2;i<=n;i++)
	{
	    int f=read();
	    add(f,i);
	}
    dfs(1);
    vis[1]=1;
    for (int i=n;i;i--)
	for (vector<int>::iterator it=st[i].begin();it!=st[i].end();it++)
	    solve(*it);
    printf("%d\n",ans);
    return 0;
}


Compiler output:
a.cc:1:5: error: 'st' does not name a type
    1 |     st[dep[x]].push_back(x);
      |     ^~
a.cc:2:5: error: expected unqualified-id before 'for'
    2 |     for (int p=now[x];p;p=pre[p])
      |     ^~~
a.cc:2:23: error: 'p' does not name a type
    2 |     for (int p=now[x];p;p=pre[p])
      |                       ^
a.cc:2:25: error: 'p' does not name a type
    2 |     for (int p=now[x];p;p=pre[p])
      |                         ^
a.cc:8:1: error: expected declaration before '}' token
    8 | }
      | ^
a.cc: In function 'void solve(int)':
a.cc:12:21: error: 'k' was not declared in this scope
   12 |     for (int i=1;i<=k;i++)
      |                     ^
a.cc:14:17: error: 'vis' was not declared in this scope
   14 |             if (vis[x]) return;
      |                 ^~~
a.cc:15:13: error: 'vis' was not declared in this scope
   15 |             vis[x]=1;
      |             ^~~
a.cc:16:15: error: 'fa' was not declared in this scope
   16 |             x=fa[x];
      |               ^~
a.cc:18:5: error: 'ans' was not declared in this scope
   18 |     ans+=(x!=1);
      |     ^~~
a.cc: In function 'int main()':
a.cc:23:5: error: 'n' was not declared in this scope
   23 |     n=read(),k=read();
      |     ^
a.cc:23:7: error: 'read' was not declared in this scope
   23 |     n=read(),k=read();
      |       ^~~~
a.cc:23:14: error: 'k' was not declared in this scope
   23 |     n=read(),k=read();
      |              ^
a.cc:24:28: error: 'ans' was not declared in this scope
   24 |     int x=read();if (x!=1) ans=1;
      |                            ^~~
a.cc:28:13: error: 'add' was not declared in this scope
   28 |             add(f,i);
      |             ^~~
a.cc:30:5: error: 'dfs' was not declared in this scope
   30 |     dfs(1);
      |     ^~~
a.cc:31:5: error: 'vis' was not declared in this scope
   31 |     vis[1]=1;
      |     ^~~
a.cc:33:14: error: 'vector' was not declared in this scope
   33 |         for (vector<int>::iterator it=st[i].begin();it!=st[i].end();it++)
      |              ^~~~~~
a.cc:33:21: error: expected primary-expression before 'int'
   33 |         for (vector<int>::iterator it=st[i].begin();it!=st[i].end();it++)
      |                     ^~~
a.cc:33:53: error: 'it' was not declared in this scope; did you mean 'i'?
   33 |         for (vector<int>::iterator it=st[i].begin();it!=st[i].end();it++)
      |                                                     ^~
      |                                                     i
a.cc:33:57: error: 'st' was not declared in this scope; did you mean 'std'?
   33 |         for (vector<int>::iterator it=st[i].begin();it!=st[i].end();it++)
      |                                                         ^~
      |                                                         std
a.cc:35:19: error: 'ans' was not declared in this scope
   35 |     printf("%d\n",ans);
      |                   ^~~
a.cc:35:5: error: 'printf' was not declared in this scope
   35 |     printf("%d\n",ans);
      |     ^~~~~~
a.cc:1:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
  +++ |+#include <cstdio>
    1 |     st[dep[x]].push_back(x);