criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include <bits/stdc++.h>
using namespace std;

#define pb push_back

const int N = 100100;

int n, k, ans, par[N];
vector<int> g[N];

int dfs(int v, int p = -1) {
	int res = 0;
	for (int to: g[v]) {
		if (to == p) continue;
		res = max(res, dfs(to, v));
	}
	if (res == k - 1 && par[v] != 1) {
		ans++;
		return 0;
	}
	return res + 1;
}

int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> par[i];
		if (i != 1) g[par[i]].pb(i);
		else ans += x != 1;
	}
	dfs(1);
	cout << ans;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:29:29: error: 'x' was not declared in this scope
   29 |                 else ans += x != 1;
      |                             ^
Language: C++

#include <bits/stdc++.h>
using namespace std;

#define pb push_back

const int N = 100100;

int n, k, ans;
vector<int> g[N];
bool used[N];

void dfs(int v, int d = 0) {
	used[v] = true;
	if (d - mns == k + 1) {
		ans++;
		d = 0;
	}
	for (int to: g[v])
		if (!used[to]) dfs(to, d + 1);
}

int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		int x; cin >> x;
		if (i != 1) g[x].pb(i);
		else ans += x != 1;
	}
	dfs(1);
	cout << ans;
}


Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:14:17: error: 'mns' was not declared in this scope; did you mean 'ans'?
   14 |         if (d - mns == k + 1) {
      |                 ^~~
      |                 ans
Language: C++

#include <bits/stdc++.h>
using namespace std;

#define pb push_back

const int N = 100100;

int n, k, ans;
vector<int> g[N];
bool used[N];

void dfs(int v, int d = 0) {
	used[v] = true;
	if (d - mns == k + 1) {
		ans++;
		d = 0;
	}
	for (int to: g[v])
		if (!used[to]) dfs(to, d + 1, mns);
}

int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		int x; cin >> x;
		if (i != 1) g[x].pb(i);
		else ans += x != 1;
	}
	dfs(1);
	cout << ans;
}


Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:14:17: error: 'mns' was not declared in this scope; did you mean 'ans'?
   14 |         if (d - mns == k + 1) {
      |                 ^~~
      |                 ans
a.cc:19:47: error: 'mns' was not declared in this scope; did you mean 'ans'?
   19 |                 if (!used[to]) dfs(to, d + 1, mns);
      |                                               ^~~
      |                                               ans
Language: C++

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cassert>
#include <bitset>
#include <fstream>
#include <cstring>
#include <stack>

using namespace std;

#define fst first
#define snd second
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define ld long double

const ld pi = acos(-1);

template<typename T>
T abs(T x) {
    return x > 0 ? x : -x;
}

template<typename T>
T sqr(T x) {
    return x * x;
}

template<typename T>
ostream& operator << (ostream &s, const vector<T> &x) {
    s << "[";
    for (auto it : x) {
        s << it << ", ";
    }
    s << "]";
    return s;
}

template<typename T>
ostream& operator << (ostream &s, const set<T> &x) {
    s << "{";
    for (auto it : x) {
        s << it << ", ";
    }
    s << "}";
    return s;
}


template<typename U, typename V>
ostream& operator << (ostream &s, const pair<U, V> &x) {
    s << "(" << x.fst << ", " << x.snd << ")";
    return s;
}

template<typename T>
bool chmax(T &x, const T &y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T &x, const T &y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}

//---------------------------------------------------------------------

const int maxn = 1e5 + 5;
vector<int> g[maxn];
int ans = 0;
int k;

int dfs(int v) {
    int depth = 0;

    for (int to : g[v]) {
        int r = 1 + dfs(to);
        if (r == k && v != 1) {
            ans++;
        } else {
            chmax(depth, r);
        }
    }
    //cout << v << " " << depth << endl;
    return depth;
}

int main() {
    srand(time(NULL));
    retry:
#ifdef LOCAL
    freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
#else
    //freopen("sum.in", "r", stdin);
	//freopen("sum.out", "w", stdout);
#endif

    int n;
    scanf("%d", &n);
    cin >> k;

    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }

    if (a[1] != 1) {
        a[1] = 1;
        ans++;
    }

    for (int i = 2; i <= n; i++) {
        g[a[i]].pb(i);
    }

    dfs(1);
    cout << ans << endl;


    return 0;
}





Compiler output:
a.cc:23:15: error: 'acos' was not declared in this scope
   23 | const ld pi = acos(-1);
      |               ^~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second
//#define endl '\n' 

int n,k;
int it[100001];
vector<int> adj[100001];
int co=0;
int ss[100001];
int endd[100001];
vector<pair<int,int>> ss3;
int par[100001];
set<int> cur2;
int ss2[100001];
int vis[100001];
void dfs(int no,int parr=-1,int levv=0){
	ss[no]=co;
	ss2[co]=no;
	par[no]=parr;
	co++;
	//cout<<no<<":"<<endl;
	ss3.pb({levv,no});
	for(auto j:adj[no]){
		if(j!=parr){
			dfs(j,no,levv+1);
		}
	}
	endd[no]=co-1;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int ans=0;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>it[i];
		it[i]--;
		if(i==0){
			if(it[i]!=0){
				ans+=1;
				it[i]=0;
			}
		}
		else{
			adj[it[i]].pb(i);
		}
	}
	dfs(0);
	sort(ss3.begin(),ss3.end());
	for(int i=0;i<n;i++){
		cur2.insert(i);
	}
	reverse(ss3.begin(),ss3.end());
	for(auto j:ss3){
		if(j.a<=k){
			continue;
		}
		if(vis[j.b]){
			continue;
		}
		int cur=j.b;
		for(int i=0;i<k-1;i++){
			cur=par[cur];
		}
		for(int i=ss[cur];i<=endd[cur];i++){
			assert(vis[ss2[i]]==0)
			vis[ss2[i]]=1;
		}
		/*auto jj=cur2.lower_bound(ss[cur]);
		while(true){
			if(jj==cur2.end()){
				break;
			}
			if(*jj>endd[cur]){
				break;
			}
			vis[ss2[*jj]]=1;
			jj++;
		}*/
		ans+=1;
	///	cout<<j.a<<":"<<j.b<<":"<<cur<<endl;
	}
	cout<<ans;






	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:72:25: error: expected ';' before 'vis'
   72 |                         vis[ss2[i]]=1;
      |                         ^~~
Language: C++

#include <iostream>
#include <vector>
using namespace std;
const int maxSize=44000;
vector<int> graph[maxSize];
bool visited[maxSize][maxSize];
int distances[maxSize][maxSize], amount, required;
vector<int> exceeded;
void fillingGraph()
{
	cin>>amount>>required;
	int vertex0;
	for(int i=1; i<=amount; ++i)
	{
		cin>>vertex0;
		graph[i].push_back(vertex0);
	}
	return;
}
void dfs(int root, int current, int distance)
{
	visited[root][current]=true;
	for(int next : graph[current])
	{
		if(!visited[root][next])
		{
			dfs(root, next, distance+1);
		}
	}
	distances[root][current]=distance;
	return;
}
void usingDfs()
{
	for(int point=1; point<=amount; ++point)
	{
		dfs(point, point, 0);
	}
	for(int i=1; i<=amount; ++i)
	{
		for(int j=1; j<=amount; ++j)
		{
			if(distances[i][1]>required)
			{
				exceeded.push_back(distances[i][1]);
			}
		}
	}
	int minimum;
	if(!exceeded.empty())
	{
		minimum=exceeded[0];
		for(int item : exceeded)
		{
			minimum=min(minimum, item);
		}
	}
	else
	{
		minimum=0;
	}
	cout<<minimum;
	return;
}
int main()
{
	fillingGraph();
	usingDfs();
	return 0;
}


Compiler output:
/tmp/ccBA9oq2.o: in function `fillingGraph()':
a.cc:(.text+0xb): relocation truncated to fit: R_X86_64_PC32 against symbol `amount' defined in .bss section in /tmp/ccBA9oq2.o
a.cc:(.text+0x27): relocation truncated to fit: R_X86_64_PC32 against symbol `required' defined in .bss section in /tmp/ccBA9oq2.o
a.cc:(.text+0x87): relocation truncated to fit: R_X86_64_PC32 against symbol `amount' defined in .bss section in /tmp/ccBA9oq2.o
/tmp/ccBA9oq2.o: in function `usingDfs()':
a.cc:(.text+0x1d3): relocation truncated to fit: R_X86_64_PC32 against symbol `amount' defined in .bss section in /tmp/ccBA9oq2.o
a.cc:(.text+0x206): relocation truncated to fit: R_X86_64_PC32 against symbol `required' defined in .bss section in /tmp/ccBA9oq2.o
a.cc:(.text+0x22e): relocation truncated to fit: R_X86_64_PC32 against symbol `exceeded' defined in .bss section in /tmp/ccBA9oq2.o
a.cc:(.text+0x240): relocation truncated to fit: R_X86_64_PC32 against symbol `amount' defined in .bss section in /tmp/ccBA9oq2.o
a.cc:(.text+0x24f): relocation truncated to fit: R_X86_64_PC32 against symbol `amount' defined in .bss section in /tmp/ccBA9oq2.o
a.cc:(.text+0x25b): relocation truncated to fit: R_X86_64_PC32 against symbol `exceeded' defined in .bss section in /tmp/ccBA9oq2.o
a.cc:(.text+0x27a): relocation truncated to fit: R_X86_64_PC32 against symbol `exceeded' defined in .bss section in /tmp/ccBA9oq2.o
a.cc:(.text+0x28e): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status
Language: C++

#include <iostream>
#include <vector>
using namespace std;
const int maxSize=44000;
vector<int> graph[maxSize];
bool visited[maxSize][maxSize];
int distances[maxSize][maxSize], amount, required;
vector<int> exceeded;
void fillingGraph()
{
	cin>>amount>>required;
	int vertex0;
	for(int i=1; i<=amount; ++i)
	{
		cin>>vertex0;
		graph[i].push_back(vertex0);
	}
	return;
}
void dfs(int root, int current, int distance)
{
	visited[root][current]=true;
	for(int next : graph[current])
	{
		if(!visited[root][next])
		{
			dfs(root, next, distance+1);
		}
	}
	distances[root][current]=distance;
	return;
}
void usingDfs()
{
	for(int point=1; point<=amount; ++point)
	{
		dfs(point, point, 0);
	}
	for(int i=1; i<=amount; ++i)
	{
		for(int j=1; j<=amount; ++j)
		{
			if(distances[i][1]>required)
			{
				exceeded.push_back(distances[i][1]);
			}
		}
	}
	int minimum;
	if(!exceeded.empty())
	{
		minimum=exceeded[0];
		for(int item : exceeded)
		{
			minimum=min(minimum, item);
		}
	}
	else
	{
		minimum=0;
	}
	cout<<minimum;
	return;
}
int main()
{
	fillingGraph();
	usingDfs();
	return 0;
}


Compiler output:
/tmp/cczQfPx4.o: in function `fillingGraph()':
a.cc:(.text+0xb): relocation truncated to fit: R_X86_64_PC32 against symbol `amount' defined in .bss section in /tmp/cczQfPx4.o
a.cc:(.text+0x27): relocation truncated to fit: R_X86_64_PC32 against symbol `required' defined in .bss section in /tmp/cczQfPx4.o
a.cc:(.text+0x87): relocation truncated to fit: R_X86_64_PC32 against symbol `amount' defined in .bss section in /tmp/cczQfPx4.o
/tmp/cczQfPx4.o: in function `usingDfs()':
a.cc:(.text+0x1d3): relocation truncated to fit: R_X86_64_PC32 against symbol `amount' defined in .bss section in /tmp/cczQfPx4.o
a.cc:(.text+0x206): relocation truncated to fit: R_X86_64_PC32 against symbol `required' defined in .bss section in /tmp/cczQfPx4.o
a.cc:(.text+0x22e): relocation truncated to fit: R_X86_64_PC32 against symbol `exceeded' defined in .bss section in /tmp/cczQfPx4.o
a.cc:(.text+0x240): relocation truncated to fit: R_X86_64_PC32 against symbol `amount' defined in .bss section in /tmp/cczQfPx4.o
a.cc:(.text+0x24f): relocation truncated to fit: R_X86_64_PC32 against symbol `amount' defined in .bss section in /tmp/cczQfPx4.o
a.cc:(.text+0x25b): relocation truncated to fit: R_X86_64_PC32 against symbol `exceeded' defined in .bss section in /tmp/cczQfPx4.o
a.cc:(.text+0x27a): relocation truncated to fit: R_X86_64_PC32 against symbol `exceeded' defined in .bss section in /tmp/cczQfPx4.o
a.cc:(.text+0x28e): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status
Language: C++

#include <iostream>
#include <vector>
using namespace std;
const int maxSize=400000;
vector<int> graph[maxSize];
bool visited[maxSize][maxSize];
int distances[maxSize][maxSize], amount, required;
vector<int> exceeded;
void fillingGraph()
{
	cin>>amount>>required;
	int vertex0;
	for(int i=1; i<=amount; ++i)
	{
		cin>>vertex0;
		graph[i].push_back(vertex0);
	}
	return;
}
void dfs(int root, int current, int distance)
{
	visited[root][current]=true;
	for(int next : graph[current])
	{
		if(!visited[root][next])
		{
			dfs(root, next, distance+1);
		}
	}
	distances[root][current]=distance;
	return;
}
void usingDfs()
{
	for(int point=1; point<=amount; ++point)
	{
		dfs(point, point, 0);
	}
	for(int i=1; i<=amount; ++i)
	{
		for(int j=1; j<=amount; ++j)
		{
			if(distances[i][1]>required)
			{
				exceeded.push_back(distances[i][1]);
			}
		}
	}
	int minimum;
	if(!exceeded.empty())
	{
		minimum=exceeded[0];
		for(int item : exceeded)
		{
			minimum=min(minimum, item);
		}
	}
	else
	{
		minimum=0;
	}
	cout<<minimum;
	return;
}
int main()
{
	fillingGraph();
	usingDfs();
	return 0;
}


Compiler output:
/tmp/ccrv7OdW.o: in function `fillingGraph()':
a.cc:(.text+0xb): relocation truncated to fit: R_X86_64_PC32 against symbol `amount' defined in .bss section in /tmp/ccrv7OdW.o
a.cc:(.text+0x27): relocation truncated to fit: R_X86_64_PC32 against symbol `required' defined in .bss section in /tmp/ccrv7OdW.o
a.cc:(.text+0x87): relocation truncated to fit: R_X86_64_PC32 against symbol `amount' defined in .bss section in /tmp/ccrv7OdW.o
/tmp/ccrv7OdW.o: in function `dfs(int, int, int)':
a.cc:(.text+0x19b): relocation truncated to fit: R_X86_64_PC32 against symbol `distances' defined in .bss section in /tmp/ccrv7OdW.o
/tmp/ccrv7OdW.o: in function `usingDfs()':
a.cc:(.text+0x1d3): relocation truncated to fit: R_X86_64_PC32 against symbol `amount' defined in .bss section in /tmp/ccrv7OdW.o
a.cc:(.text+0x1fd): relocation truncated to fit: R_X86_64_PC32 against symbol `distances' defined in .bss section in /tmp/ccrv7OdW.o
a.cc:(.text+0x206): relocation truncated to fit: R_X86_64_PC32 against symbol `required' defined in .bss section in /tmp/ccrv7OdW.o
a.cc:(.text+0x221): relocation truncated to fit: R_X86_64_PC32 against symbol `distances' defined in .bss section in /tmp/ccrv7OdW.o
a.cc:(.text+0x22e): relocation truncated to fit: R_X86_64_PC32 against symbol `exceeded' defined in .bss section in /tmp/ccrv7OdW.o
a.cc:(.text+0x240): relocation truncated to fit: R_X86_64_PC32 against symbol `amount' defined in .bss section in /tmp/ccrv7OdW.o
a.cc:(.text+0x24f): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status
Language: C++

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
#include<map>
#include<deque>
#include<set>
#define inf 1e9
#define eps 1e-6
#define N 200010
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
	char ch=getchar();
	ll s=0,w=1;
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
	return s*w;
}
struct edge
{
	int next,to;
}e[N<<1];
int head[N],cnt;
int n,k,ans,maxn[N];
inline void add_edge(int from,int to){e[++cnt]=(edge){head[from],to};head[from]=cnt;}
void dfs(int now)
{
	for(register int i=head[now];i;i=e[i].next)
	{
		dfs(e[i].to);maxn[now]=max(maxn[e[i].to]+1,maxn[now]);
	}
	if(maxn[now]==k){ans++;maxn[now]=-1;}
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read(),k=read();
	for(register int i=1;i<=n;i++)
	{
		int x=read();
		if(i==1)ans+=(x!=1);
		else add_edge(x,i);
	}
	dfs(1,0);
	printf("%d\n",ans);
	return 0;
}


Compiler output:
a.cc: In function 'void dfs(int)':
a.cc:35:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   35 |         for(register int i=head[now];i;i=e[i].next)
      |                          ^
a.cc: In function 'int main()':
a.cc:46:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   46 |         for(register int i=1;i<=n;i++)
      |                          ^
a.cc:52:12: error: too many arguments to function 'void dfs(int)'
   52 |         dfs(1,0);
      |         ~~~^~~~~
a.cc:33:6: note: declared here
   33 | void dfs(int now)
      |      ^~~
Language: C++

#include<cstdio>
using namespace std;

typedef const int& cint;
const int MAXN = 100010;

int N, K, ans;

struct Edge{
	int to, nxt;
	
	Edge(){}
	
	Edge(cint to_, cint nxt_){to = to_, nxt = nxt_;}
}ed[MAXN << 1];
int head[MAXN], tot;
int par[MAXN], dep[MAXN], mx[MAXN];

inline void add(cint u, cint v){
	ed[++tot] = Edge(v, head[u]), head[u] = tot;
	ed[++tot] = Edge(u, head[v]), head[v] = tot;
}

inline chkmax(int& a, int b){if (b > a) a = b;}

void dfs(int u){
	mx[u] = dep[u];
	int tmp, v;
	for (tmp = head[u]; tmp; tmp = ed[tmp].nxt){
		v = ed[tmp].to;
		if (v != par[u])
			dep[v] = dep[u] + 1, dfs(v), chkmax(mx[u], mx[v]);
	}
	if (mx[u] - dep[u] == K - 1 && par[u] != 1)
		++ans, mx[u] = 0;
}

int main(){
	scanf("%d %d", &N, &K);
	for (int i = 1; i <= N; ++i)
		scanf("%d", &par[i]);
	if (par[1] != 1)
		++ans, par[1] = 1;
	for (int i = 2; i <= N; ++i)
		add(i, par[i]);
	dfs(1);
	printf("%d", ans);
	return 0;
} 


Compiler output:
a.cc:24:8: error: ISO C++ forbids declaration of 'chkmax' with no type [-fpermissive]
   24 | inline chkmax(int& a, int b){if (b > a) a = b;}
      |        ^~~~~~
a.cc: In function 'int chkmax(int&, int)':
a.cc:24:47: warning: no return statement in function returning non-void [-Wreturn-type]
   24 | inline chkmax(int& a, int b){if (b > a) a = b;}
      |                                               ^
Language: C++

#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef pair<int, int> P;

struct Graph
{
    int n;
    vector<vector<int>> g;
    
    Graph(int n) : n(n){
        g.resize(n);
    }
    
    void init(int n_){
        n = n_;
        g.resize(n_);
    }
    
    void add_edge(int from, int to){
        g[from].push_back(to);
    }
};

struct Tree	//create tree(directed) from graph(undirected)
{
    int n;
    int root;
    vector<vector<int>> t;
    vector<int> par;
    vector<int> dpt;
    
    void init(Graph &g, int root_){
        n = g.n;
        root = root_;
        t.resize(n);
        par.resize(n);
        dpt.resize(n);
        fill(dpt.begin(), dpt.end(), -1);
        queue<int> que;
        par[root] = -1;
        dpt[root] = 0;
        que.push(root);
        while(que.size()){
            int pa = que.front();
            que.pop();
            for(int ch : g.g[pa]){
                if(dpt[ch] == -1){
                    t[pa].push_back(ch);
                    par[ch] = pa;
                    dpt[ch] = dpt[pa] + 1;
                    que.push(ch);
                }
            }
        }
    }

    Tree(){}
    
    Tree(Graph &g, int root_){
        init(g, root_);
    }
};

int main()
{
    int n, k;
    cin >> n >> k;
    int ans = 0;
    Graph g(n);
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        a--;
        if(i == 0){
            if(a != 0) ans++;
        }
        else{
            g.add_edge(i, a);
            g.add_edge(a, i);
        }
    }
    Tree t(g, 0);
    P p[100005];
    bool b[100005]{0};
    for(int i = 0; i < n; i++) p[i] = P(t.dpt[i], i);
    sort(p, p + n, greater<P>());
    for(int i = 0; i < n; i++){
        int u = p[i].second;
        if(b[u]) continue;
        for(int i = 0; i < k - 1; i++){
            if(u == 0) break;
            u = t.par[u];
        }
        if(u != 0 && t.par[u] != 0) ans++;
        queue<int> que;
        que.push(u);
        b[u] = true;
        while(que.size()){
            int v = que.front();
            que.pop();
            for(int w : t.t[v]){
                if(!b[w]){
                    b[w] = true;
                    que.push(w);
                }
            }
        }
    }
    cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:88:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   88 |     sort(p, p + n, greater<P>());
      |     ^~~~
      |     short
Language: C++

//#include<bits/stdc++.h>
#include<iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include<bitset>
#include<list>
#include<cassert>
#include<numeric>

using namespace std;

const int N = 1e5 + 5;
vector<int> rgraph[N];
vector<int> rnk[N];
int dp[N];
int a[N];
int h[N];
int g[N];
int p;
bool mark[N];
bool ok[N];
int n, k; 
int ans;

void bfs(int v)
{
	queue<int> q;
	q.push(v);
	while (q.size())
	{
		int x = q.front();
		q.pop();
		for (int i = 0; i < rgraph[x].size(); i++)
		{
			int u = rgraph[x][i];
			if (!mark[u])
			{
				if (u != x)
				{
					h[u] = h[x] + 1;
				}
				rnk[h[u]].push_back(u);
				mark[u] = true;
				q.push(u);
			}
		}
	}
}

void dfs(int v)
{
	mark[v] = true;
	dp[v] = h[v];
	for (int i = 0; i < rgraph[v].size(); i++)
	{
		int u = rgraph[v][i];
		if (!mark[u])
		{
			dfs(u);
			dp[v] = max(dp[v], dp[u]);
		}
	}
}

void solver(int v, int par)
{
	mark[v] = true;
	for (int i = 0; i < rgraph[v].size(); i++)
	{
		int u = rgraph[v][i];
		if (!mark[u])
		{
			if (dp[u] - h[u] == k - 1 && v != 0)
			{
				ok[u] = true;
				ans++;
			}
			else
			{
				g[v] = max(g[v], dp[u]);
			}
			solver(u, v);
		}
	}
	if (g[v] - h[v] == k - 1 && !ok[v] && par != 0)
	{
		ans++;
	}
}

int main() 
{
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		int v;
		cin >> v;
		a[i] = v;
		v--;
		rgraph[v].push_back(i);
	}
	if (a[0] != 1)
	{
		ans++;
		rgraph[0].push_back(0);
		a[0] = 1;
	}
	bfs(0);
	memset(mark, 0, sizeof mark);
	dfs(0);
	memset(mark, 0, sizeof mark);
	solver(0, 0);
	cout << ans << endl;




}



Compiler output:
a.cc: In function 'int main()':
a.cc:115:9: error: 'memset' was not declared in this scope
  115 |         memset(mark, 0, sizeof mark);
      |         ^~~~~~
a.cc:15:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
   14 | #include<numeric>
  +++ |+#include <cstring>
   15 |
Language: C++

//#include<bits/stdc++.h>
#include<iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include<bitset>
#include<list>
#include<cassert>
#include<numeric>

using namespace std;

const int N = 1e5 + 5;
vector<int> rgraph[N];
vector<int> rnk[N];
int dp[N];
int a[N];
int h[N];
int p;
bool mark[N];
int n, k; 
int ans;

void bfs(int v)
{
	queue<int> q;
	q.push(v);
	while (q.size())
	{
		int x = q.front();
		q.pop();
		for (int i = 0; i < rgraph[x].size(); i++)
		{
			int u = rgraph[x][i];
			if (!mark[u])
			{
				if (u != x)
				{
					h[u] = h[x] + 1;
				}
				rnk[h[u]].push_back(u);
				mark[u] = true;
				q.push(u);
			}
		}
	}
}

void dfs(int v)
{
	mark[v] = true;
	dp[v] = h[v];
	for (int i = 0; i < rgraph[v].size(); i++)
	{
		int u = rgraph[v][i];
		if (!mark[u])
		{
			dfs(u);
			dp[v] = max(dp[v], dp[u]);
		}
	}
}

void calc(int v)
{
	mark[v] = true;
	for (int i = 0; i < rgraph[v].size(); i++)
	{
		int u = rgraph[v][i];
		if (!mark[u])
		{
			calc(u);
		}
	}
}

void solver(int v, int l)
{
	h[v] = h[v] - l;
	mark[v] = true;
	int less = 0;
	less += h[v] - 1;
	int cnt = 0;
	for (int i = 0; i < rgraph[v].size(); i++)
	{
		int u = rgraph[v][i];
		if (!mark[u])
		{
			if (dp[u] - l > k && dp[u] - l - less <= k)
			{
				cnt++;
			}
		}
	}
	if (cnt > 1 || h[v] > k)
	{
		if (a[0] == v + 1)
		{
			h[0] = 0;
			ans++;
		}
		ans++;
		//cout << v << " " << less << " " << l << " " << h[v] << endl;;
		for (int i = 0; i < rgraph[v].size(); i++)
		{
			int u = rgraph[v][i];
			if (!mark[u])
			{
				if (dp[u] - l - less > k)
				{
					solver(u, l + h[v] - p);
				}
				else
				{
					calc(u);
				}
			}
		}
	}
	else
	{
		for (int i = 0; i < rgraph[v].size(); i++)
		{
			int u = rgraph[v][i];
			if (!mark[u])
			{
				solver(u, l);
			}
		}
	}
}

int main() 
{
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		int v;
		cin >> v;
		a[i] = v;
		v--;
		rgraph[v].push_back(i);
	}
	bfs(0);
	memset(mark, 0, sizeof mark);
	for (int i = 0; i < n; i++)
	{
		for (auto u: rnk[i])
		{
			if (!mark[u])
			{
				dfs(u);
			}
		}
	}
	memset(mark, 0, sizeof mark);
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < rnk[i].size(); i++)
		{
			int u = rnk[i][j];
			if (!mark[u])
			{
				p = i + 1;
				solver(u, 0);
			}
		}
	}
	cout << ans << endl;




}



Compiler output:
a.cc: In function 'int main()':
a.cc:150:9: error: 'memset' was not declared in this scope
  150 |         memset(mark, 0, sizeof mark);
      |         ^~~~~~
a.cc:15:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
   14 | #include<numeric>
  +++ |+#include <cstring>
   15 |
Language: C++

#include<vector>
#include<algorithm>
#include<string>
using namespace std;

#define int long long

int ans, K, X;

int dfs(vector<vector<int>> & tree, int depth, int now, int per){
  int maximum = depth;

  for(int next : tree[now]){
    maximum = max(maximum, dfs(tree, depth+1, next, now));
    // cout<<now<<" -> "<<next<<endl;
  }
  // cout<<endl;
  //cout<<"K = "<<K<<" per "<<per<<endl;
  //cout<<"now "<<now<<" depth "<<depth<<" maximum "<<maximum<<" <> "<<maximum-depth<<" ans "<<ans<<endl;

  if(now == 0){

  } else if(per == 0){
    if(maximum - depth >= K){
      ans++;
      maximum = depth-1;
    }
  }else{
    if(maximum - depth >= K-1){
      ans++;
      maximum = depth-1;
    }
  }

  //  cout<<"now "<<now<<" depth "<<depth<<" maximum "<<maximum<<" <> "<<maximum-depth<<" ans "<<ans<<endl;

  return maximum;
}

signed main(){

  int N;
  vector<int> a;
  vector<vector<int>> tree;

  cin>>N>>K;

  a.resize(N);
  tree.resize(N);

  for(int i = 0; i < N; i++){
    cin>>a[i];

    a[i]--;

    if(!i) {
      if(a[i] != 0) ans++;
      continue;
    }

    tree[a[i]].push_back(i);
    //tree[i].push_back(a[i]);

  }

  dfs(tree, 0, 0, -1);

  cout<<ans<<endl;

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:46:3: error: 'cin' was not declared in this scope
   46 |   cin>>N>>K;
      |   ^~~
a.cc:4:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    3 | #include<string>
  +++ |+#include <iostream>
    4 | using namespace std;
a.cc:68:3: error: 'cout' was not declared in this scope
   68 |   cout<<ans<<endl;
      |   ^~~~
a.cc:68:3: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:68:14: error: 'endl' was not declared in this scope
   68 |   cout<<ans<<endl;
      |              ^~~~
a.cc:4:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    3 | #include<string>
  +++ |+#include <ostream>
    4 | using namespace std;
Language: C++

int LongestIncreasingSubsequenceLength(std::vector<int>& v)  
{  
    if (v.size() == 0)  
        return 0;  
  
    std::vector<int> tail(v.size(), 0);  
    int length = 1; // always points empty slot in tail  
  
    tail[0] = v[0];  
      
    for (int i = 1; i < v.size(); i++) {  
  
            // Do binary search for the element in  
            // the range from begin to begin + length 
        auto b = tail.begin(), e = tail.begin() + length; 
        auto it = lower_bound(b, e, v[i]);  
              
        // If not present change the tail element to v[i]  
        if (it == tail.begin() + length) 
        tail[length++] = v[i];  
        else   
        *it = v[i];  
    }  
  
    return length;  
}  

Compiler output:
a.cc:1:45: error: 'vector' is not a member of 'std'
    1 | int LongestIncreasingSubsequenceLength(std::vector<int>& v)
      |                                             ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | int LongestIncreasingSubsequenceLength(std::vector<int>& v)
a.cc:1:52: error: expected primary-expression before 'int'
    1 | int LongestIncreasingSubsequenceLength(std::vector<int>& v)
      |                                                    ^~~
Language: C++

#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9,MOD = 1e9+7,ohara = 1e6;
const ll LINF = 1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos,k;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl,visited[ohara];
struct edge{int to,cost;};
vector<ll> g[ohara];

//-------------------------↓↓↓↓↓↓------------------------

void dfs(ll now,ll depth){
    //if(depth>k+1)return;
    if(visited[now])return;
    //cout<<"now "<<now<<" depth "<<depth<<"\n";
    visited[now]=true;
    if(depth==k&&a[now]!=0)ans++,depth=1;
    if(depth==k)ans++,depth=1;
    rep(i,Size(g[now])){
        ll to=g[now][i];
        dfs(to,depth+1);
    }
    return;
}

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
      
    cin>>n>>k;
    rep(i,n){
        cin>>a[i];
        if(i==0&&a[i]!=1)ans=1;
        if(i==a[ohara]-1)continue;
       if(i==0)continue;
        a[i]--;
        g[a[i]].push_back(i);
    }
    dfs(0,0);
    Cout(ans);
    return 0;
}


Compiler output:
a.cc: In function 'void dfs(ll, ll)':
a.cc:32:19: error: invalid types 'll {aka long long int}[ll {aka long long int}]' for array subscript
   32 |     if(depth==k&&a[now]!=0)ans++,depth=1;
      |                   ^
a.cc: In function 'int main()':
a.cc:47:15: error: invalid types 'll {aka long long int}[ll {aka long long int}]' for array subscript
   47 |         cin>>a[i];
      |               ^
a.cc:48:19: error: invalid types 'll {aka long long int}[ll {aka long long int}]' for array subscript
   48 |         if(i==0&&a[i]!=1)ans=1;
      |                   ^
a.cc:49:16: error: invalid types 'll {aka long long int}[const int]' for array subscript
   49 |         if(i==a[ohara]-1)continue;
      |                ^
a.cc:51:10: error: invalid types 'll {aka long long int}[ll {aka long long int}]' for array subscript
   51 |         a[i]--;
      |          ^
a.cc:52:12: error: invalid types 'll {aka long long int}[ll {aka long long int}]' for array subscript
   52 |         g[a[i]].push_back(i);
      |            ^
Language: C++

#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9,MOD = 1e9+7,ohara = 1e6;
const ll LINF = 1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos,k;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl,visited[ohara];
struct edge{int to,cost;};
vector<ll> g[ohara];

//-------------------------↓↓↓↓↓↓------------------------

void dfs(ll now,ll depth){
    //if(depth>k+1)return;
    if(visited[now])return;
    //cout<<"now "<<now<<" depth "<<depth<<"\n";
    visited[now]=true;
    if(depth==k&&a[now]!=0)ans++,depth=1;
    if(depth==k)ans++,depth=1;
    rep(i,Size(g[now])){
        ll to=g[now][i];
        dfs(to,depth+1);
    }
    return;
}

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
      
    cin>>n>>k;
    rep(i,n){
        cin>>a;
        if(i==0&&a!=1)ans=1;
        if(i==a-1)continue;
       if(i==0)continue;
        a--;
        g[a].push_back(i);
    }
    dfs(0,0);
    Cout(ans);
    return 0;
}


Compiler output:
a.cc: In function 'void dfs(ll, ll)':
a.cc:32:19: error: invalid types 'll {aka long long int}[ll {aka long long int}]' for array subscript
   32 |     if(depth==k&&a[now]!=0)ans++,depth=1;
      |                   ^
Language: C++

#include<bits/stdc++.h>
vector<int> v[1<<17];int n,k,a,y,t,i;
int s(int x,int p){int r=0;for(t:v[x])r=max(r,s(t,x));a+=++r>=k&&p;return r%k;}
int main(){std::cin>>n>>k>>y;for(a=(y!=1);std::cin>>y;v[y-1].push_back(++i));s(0,0);std::cout<<a;}

Compiler output:
a.cc:2:1: error: 'vector' does not name a type
    2 | vector<int> v[1<<17];int n,k,a,y,t,i;
      | ^~~~~~
a.cc: In function 'int s(int, int)':
a.cc:3:33: error: found ':' in nested-name-specifier, expected '::'
    3 | int s(int x,int p){int r=0;for(t:v[x])r=max(r,s(t,x));a+=++r>=k&&p;return r%k;}
      |                                 ^
      |                                 ::
a.cc:3:32: error: 't' is not a class, namespace, or enumeration
    3 | int s(int x,int p){int r=0;for(t:v[x])r=max(r,s(t,x));a+=++r>=k&&p;return r%k;}
      |                                ^
a.cc:3:68: error: expected primary-expression before 'return'
    3 | int s(int x,int p){int r=0;for(t:v[x])r=max(r,s(t,x));a+=++r>=k&&p;return r%k;}
      |                                                                    ^~~~~~
a.cc:3:68: error: expected ')' before 'return'
    3 | int s(int x,int p){int r=0;for(t:v[x])r=max(r,s(t,x));a+=++r>=k&&p;return r%k;}
      |                               ~                                    ^~~~~~
      |                                                                    )
a.cc: In function 'int main()':
a.cc:4:55: error: 'v' was not declared in this scope
    4 | int main(){std::cin>>n>>k>>y;for(a=(y!=1);std::cin>>y;v[y-1].push_back(++i));s(0,0);std::cout<<a;}
      |                                                       ^
a.cc: In function 'int s(int, int)':
a.cc:3:79: warning: control reaches end of non-void function [-Wreturn-type]
    3 | int s(int x,int p){int r=0;for(t:v[x])r=max(r,s(t,x));a+=++r>=k&&p;return r%k;}
      |                                                                               ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
vector<int> v[1e6];int n,k,a,y,i=1;
int s(int x,int p=0){int r=0;for(int to:v[x])r=max(r,s(to,x));if(++r>=k&&p)a++,r=0;return r;}
int main(){cin>>n>>k>>y;if(y!=1)a++;for(;i<n;i++){cin>>y;v[y-1].push_back(i);}s(0);cout<<a;}

Compiler output:
a.cc:3:15: error: conversion from 'double' to 'long unsigned int' in a converted constant expression
    3 | vector<int> v[1e6];int n,k,a,y,i=1;
      |               ^~~
a.cc:3:15: error: could not convert '1.0e+6' from 'double' to 'long unsigned int'
    3 | vector<int> v[1e6];int n,k,a,y,i=1;
      |               ^~~
      |               |
      |               double
a.cc:3:15: error: size of array 'v' has non-integral type 'double'
Language: C++

#include<bits/stdc++.h>
using namespace std;
vector<int> v[101010];
int n,k,a,y,i=1;
int s(int x,int p=0){
    int r=0;
    for(auto to:v[x])r=max(r,s(to,x));
    if(++r>=k&&p)a++,r=0;
    return r;
}

int main(){
    cin>>n>>k>>y;
    if(y!=1)a++;
    for(;i<n;i++){
        cin>>y;
        v[x-1].push_back(i);
    }
    s(0);
    puts(a);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:17:11: error: 'x' was not declared in this scope
   17 |         v[x-1].push_back(i);
      |           ^
a.cc:20:10: error: invalid conversion from 'int' to 'const char*' [-fpermissive]
   20 |     puts(a);
      |          ^
      |          |
      |          int
In file included from /usr/include/c++/14/cstdio:42,
                 from /usr/include/c++/14/ext/string_conversions.h:45,
                 from /usr/include/c++/14/bits/basic_string.h:4154,
                 from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/stdio.h:714:30: note:   initializing argument 1 of 'int puts(const char*)'
  714 | extern int puts (const char *__s);
      |                  ~~~~~~~~~~~~^~~
Language: C++

#pragma GCC optimize(2)
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
typedef long long ll;
const int MAXN = 1e5 + 5;
const int mod = 1e9 + 7;
using namespace std;
int cot[MAXN];
int nex[MAXN];
int deq[MAXN];
int main() {
    int n, k;
    cin >> n >> k;
    int ans = 0;
    for(int i = 1; i <= n; i++)    {
        int x;
        scanf("%d",&);
        if(i == 1 && x != 1)        {
            ans++;
            continue;
        }        else        {
            nex[i] = x;
            cot[x]++;
        }
    }
    queue<int>Q;
    int t = 0, h = 0;
    for(int i = 2; i <= n; i++)
        if(!cot[i])
            Q.push(i);
    while(!Q.empty())    {
        int u = Q.front();
        Q.pop();
        if(u == 1)
            break;
        if( nex[u] != 1 && deq[u] == (k - 1) )
            ans++;
        else
            deq[nex[u]] = max(deq[nex[u]], deq[u] + 1);
        cot[ nex[u] ]--;
        if(!cot[ nex[u] ])
            Q.push( nex[u]);
    }
    cout << ans << endl;
    return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:18:21: error: expected primary-expression before ')' token
   18 |         scanf("%d",&);
      |                     ^
Language: C++

#pramga GCC optimize(2)
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
typedef long long ll;
const int MAXN = 1e5 + 5;
const int mod = 1e9 + 7;
using namespace std;
int cot[MAXN];
int nex[MAXN];
int deq[MAXN];
int main() {
    int n, k;
    cin >> n >> k;
    int ans = 0;
    for(int i = 1; i <= n; i++)    {
        int x;
        scanf("%d",&);
        if(i == 1 && x != 1)        {
            ans++;
            continue;
        }        else        {
            nex[i] = x;
            cot[x]++;
        }
    }
    queue<int>Q;
    int t = 0, h = 0;
    for(int i = 2; i <= n; i++)
        if(!cot[i])
            Q.push(i);
    while(!Q.empty())    {
        int u = Q.front();
        Q.pop();
        if(u == 1)
            break;
        if( nex[u] != 1 && deq[u] == (k - 1) )
            ans++;
        else
            deq[nex[u]] = max(deq[nex[u]], deq[u] + 1);
        cot[ nex[u] ]--;
        if(!cot[ nex[u] ])
            Q.push( nex[u]);
    }
    cout << ans << endl;
    return 0;
}



Compiler output:
a.cc:1:2: error: invalid preprocessing directive #pramga; did you mean #pragma?
    1 | #pramga GCC optimize(2)
      |  ^~~~~~
      |  pragma
a.cc: In function 'int main()':
a.cc:18:21: error: expected primary-expression before ')' token
   18 |         scanf("%d",&);
      |                     ^
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <utility>

#define MAX_V 100010
using namespace std;
vector<int> G[MAX_V];
vector<pair<int,int>> toi;
stack<int> st;
bool used[MAX_V];
int d[MAX_V],a[MAX_V],c;

void dfs(int s){
	used[s] = true;
	st.push(s);
	while(!st.empty()){
		int e = st.top();
		st.pop();
		for(int i=0;i<G[e].size();i++){
			if(!used[G[e][i]]){
				used[G[e][i]] = true;
				d[G[e][i]] = d[e]+1;
				st.push(G[e][i]);
			}
		}
		
	}
}

void dfs1(int s){
	used[s] =false;
	st.push(s);
	while(!st.empty()){
		int e = st.top();
		st.pop();
		for(int i=0;i<G[e].size();i++){
			if(used[G[e][i]]){
				used[G[e][i]] = false;
				st.push(G[e][i]);
			}
		}
	}
}
	
int main(){
	int i,j,k,ans=0,cnt,x,y;
	cin >> V >> k;
	cin >> i;
	if(i!=1){
		ans++;
	}
	for(i=1;i<V;i++){
		cin >> a[i];
		a[i]--;
		G[a[i]].push_back(i);
	}

	for(i=0;i<V;i++){
		G[i].push_back(-1);
		used[i] = false;
		d[i] = 0;
	}
	dfs(0);

	for(i=0;i<V;i++){
		if(d[i]>k){
			toi.push_back(make_pair(d[i],i));
		}
	}
	sort(toi.begin(),toi.end());

	for(i=toi.size()-1;i>=0;i--){
		if(used[toi[i].second]){
			ans ++;
			cnt = 0;
			x = toi[i].second;
			while(cnt<k-1){
				cnt++;
				y = a[x];
				x = y;
			}
			dfs1(x);
		}
	}
	cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:49:16: error: 'V' was not declared in this scope
   49 |         cin >> V >> k;
      |                ^
Language: C++

#include<cstdio>
#include<cstring>
#include<algorithm>
const int N=1e5+10;
int n,k,sum=0,count[N],q[N],h=1,t=0,fa[N],ll[N];
int read(){
    int f=1,ans=0;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){ans=ans*10+c-48;c=getchar();}
    return ans*f;
}
int main(){
    n=read();k=read();
    int a=read();if(a!=1)sum++;
    for(int i=2;i<=n;i++){
        a=read();fa[i]=a;count[a]++;
    }
    for(int i=2;i<=n;i++)if(!count[i])q[++t]=i;
    while(h<=t){
        int x=q[h];h++;
        if(x==1)break;
        if(fa[x]!=1&&ll[x]==k-1)sum++;
        else ll[fa[x]]=std::max(ll[fa[x]],ll[x]+1);
        count[fa[x]]--;
        if(!count[fa[x]])q[++t]=fa[x];
    }
    printf("%d\n",sum);
    return 0;
}

agc004 D

Compiler output:
a.cc:31:1: error: 'agc004' does not name a type
   31 | agc004 D
      | ^~~~~~
Language: C++

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

const int MAXN = 1e5 + 10;
int N, K;
vector<int> E[MAXN];
int ans;

inline int Dfs(int x) {
	int res = 1, d;
	for(register int i : E[x])
		(d = Dfs(i)) == K ? ++ans : res = max(res, d + 1);
	return res;
}

int main() {
	register int i; int x;
	scanf("%d%d", &N, &K);
	for(i = 1; i <= N; ++i)
		scanf("%d", &x),
		(i > 1) ? E[x].push_back(i), 0 : ans += x != 1;
	for(register int i : E[1]) Dfs(i);
	printf("%d\n", ans);
	return 0;
}

Compiler output:
a.cc:10:1: error: 'vector' does not name a type
   10 | vector<int> E[MAXN];
      | ^~~~~~
a.cc: In function 'int Dfs(int)':
a.cc:15:30: error: 'E' was not declared in this scope
   15 |         for(register int i : E[x])
      |                              ^
a.cc:15:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   15 |         for(register int i : E[x])
      |                          ^
a.cc: In function 'int main()':
a.cc:21:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   21 |         register int i; int x;
      |                      ^
a.cc:25:27: error: 'E' was not declared in this scope
   25 |                 (i > 1) ? E[x].push_back(i), 0 : ans += x != 1;
      |                           ^
a.cc:26:30: error: 'E' was not declared in this scope
   26 |         for(register int i : E[1]) Dfs(i);
      |                              ^
a.cc:26:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   26 |         for(register int i : E[1]) Dfs(i);
      |                          ^
Language: C++

# include <bits/stdc++.h>

using namespace std;

# define REP(i, a, b) for(int i = a; i <= b; ++ i)
# define CLR(i, a) memset(i, a, sizeof(i))
# define REPD(i, a, b) for(int i = a; i >= b; -- i)
# define REPG(i, h, x) for(int i = h[x], v; ~i; i = edge[i].next)

const int N = 1e5 + 5;

int n, k;
int head[N], cnt;
struct qwq { int v, next; } edge[N << 1];
inline void add(int u, int v) { edge[++ cnt] = (qwq) { v, head[u] }, head[u] = cnt; }

int f[N], ans;

int dfs(int x, int fa) {
	int why = 1;
	REPG(i, head, x) if((v = edge[i].v) != fa) {
		why = max(dfs(v, x) + 1, why);
	}
	if(why == k && fa != 1) { ++ ans; return why = 0; }
}

int main() {
	CLR(head, -1);
	scanf("%d%d", &n, &k);
	REP(i, 1, n) scanf("%d", &a[i]);
	REP(i, 2, n) add(a[i], i);
	dfs(1, 0);
	printf("%d\n", a[1] == 1 ? ans : ans + 1);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:30:35: error: 'a' was not declared in this scope
   30 |         REP(i, 1, n) scanf("%d", &a[i]);
      |                                   ^
a.cc:31:26: error: 'a' was not declared in this scope
   31 |         REP(i, 2, n) add(a[i], i);
      |                          ^
a.cc:33:24: error: 'a' was not declared in this scope
   33 |         printf("%d\n", a[1] == 1 ? ans : ans + 1);
      |                        ^
a.cc: In function 'int dfs(int, int)':
a.cc:25:1: warning: control reaches end of non-void function [-Wreturn-type]
   25 | }
      | ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
const int N=2e5;
int m,ans;
int head[N],nxt[N];
inline void dfs(int k,int s) {
	if (s>m) s=1,ans++;
	for (int i=head[k];i;i=nxt[i])
		dfs(i,s+1);
}
int main()
{
	int n=gi(),i,k;m=gi();
	ans=gi()!=1;
	for (i=2;i<=n;i++) nxt[i]=head[k=gi()],head[k]=i;
	dfs(1,0);
	printf("%d\n",ans);
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:13:15: error: 'gi' was not declared in this scope
   13 |         int n=gi(),i,k;m=gi();
      |               ^~
a.cc:15:14: error: 'i' was not declared in this scope
   15 |         for (i=2;i<=n;i++) nxt[i]=head[k=gi()],head[k]=i;
      |              ^
a.cc:15:40: error: 'k' was not declared in this scope
   15 |         for (i=2;i<=n;i++) nxt[i]=head[k=gi()],head[k]=i;
      |                                        ^
Language: C++


#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

int N,K;
int a[100000];

int ans = 0;
int rank[100000];

int DFS(int v){
    if(rank[v]>=0)return rank[v];
    int res = rank[a[v]]+1;
    if(res>K)ans++,res=1;
    return rank[v] = res;
}

int main(){

    cin>>N>>K;
    REP(i,N)cin>>a[i],a[i]--;
    fill_n(rank,100000,-1);
    if(a[0]!=0)ans++,a[0]=0,rank[0]=0;
    REP(i,N)DFS(i);

    cout<<ans<<endl;


    return 0;
}

Compiler output:
a.cc: In function 'int DFS(int)':
a.cc:16:8: error: reference to 'rank' is ambiguous
   16 |     if(rank[v]>=0)return rank[v];
      |        ^~~~
In file included from /usr/include/c++/14/bits/stl_pair.h:60,
                 from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:2:
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:13:5: note:                 'int rank [100000]'
   13 | int rank[100000];
      |     ^~~~
a.cc:16:26: error: reference to 'rank' is ambiguous
   16 |     if(rank[v]>=0)return rank[v];
      |                          ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:13:5: note:                 'int rank [100000]'
   13 | int rank[100000];
      |     ^~~~
a.cc:17:15: error: reference to 'rank' is ambiguous
   17 |     int res = rank[a[v]]+1;
      |               ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:13:5: note:                 'int rank [100000]'
   13 | int rank[100000];
      |     ^~~~
a.cc:19:12: error: reference to 'rank' is ambiguous
   19 |     return rank[v] = res;
      |            ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:13:5: note:                 'int rank [100000]'
   13 | int rank[100000];
      |     ^~~~
a.cc: In function 'int main()':
a.cc:26:12: error: reference to 'rank' is ambiguous
   26 |     fill_n(rank,100000,-1);
      |            ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:13:5: note:                 'int rank [100000]'
   13 | int rank[100000];
      |     ^~~~
a.cc:27:29: error: reference to 'rank' is ambiguous
   27 |     if(a[0]!=0)ans++,a[0]=0,rank[0]=0;
      |                             ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:13:5: note:                 'int rank [100000]'
   13 | int rank[100000];
      |     ^~~~