Submission #3783690


Source Code Expand

    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;
}

Submission Info

Submission Time
Task D - Teleporter
User AlseoRoplyer
Language C++14 (GCC 5.4.1)
Score 0
Code Size 588 Byte
Status CE

Compile Error

./Main.cpp:1:5: error: ‘st’ does not name a type
     st[dep[x]].push_back(x);
     ^
./Main.cpp:2:5: error: expected unqualified-id before ‘for’
     for (int p=now[x];p;p=pre[p])
     ^
./Main.cpp:2:23: error: ‘p’ does not name a type
     for (int p=now[x];p;p=pre[p])
                       ^
./Main.cpp:2:25: error: ‘p’ does not name a type
     for (int p=now[x];p;p=pre[p])
                         ^
./Main.cpp:8:1: error: expected declaration before ‘}’ token
 }
 ^