Language: C++

x#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n;i++)
using namespace std;
#define int long long
signed main(){
    int n,k;
    typedef pair<int,int> pii;
    cin>>n>>k;
    vector<bool>flag(n+1,true);
    vector<bool>IsPrint(n+1,true);
    vector<pii>mp(n+1);
    int ans=0;
    rep(i,n){
        int temp; cin>>temp;
        if(temp==0){ans++; mp[i+1]=pii(0,0);flag[i+1]=false; continue;}
        mp[i+1]=pii(temp,mp[temp].second+1);
        flag[temp]=false;
    }
    vector<int>yebi;
    vector<int>dp(n+1,0);
    rep(i,n)if(flag[i+1])yebi.push_back(i+1);
    rep(z,yebi.size()){
        int i=yebi[z];
        ans++;
        IsPrint[i]=false;
        flag[i]=false;
        pii next=mp[i];
        for(int i=1;i<=k-1;i++){
            if(mp[next.first].second==0)break;
            if(IsPrint[next.first]==false){
                if(dp[next.first]>=k-1-i)break;
                dp[next.first]=max(dp[next.first],k-1-i);
                IsPrint[next.first]=false;
                next=mp[next.first];
                continue;
            }
            IsPrint[next.first]=false;
            flag[next.first]=false;
            ans++;
            next=mp[next.first];
        }
    }
    cout<<ans<<endl;
}


Compiler output:
a.cc:1:2: error: stray '#' in program
    1 | x#include<bits/stdc++.h>
      |  ^
a.cc:1:1: error: 'x' does not name a type
    1 | x#include<bits/stdc++.h>
      | ^
a.cc: In function 'int main()':
a.cc:7:13: error: 'pair' does not name a type
    7 |     typedef pair<int,int> pii;
      |             ^~~~
a.cc:8:5: error: 'cin' was not declared in this scope
    8 |     cin>>n>>k;
      |     ^~~
a.cc:9:5: error: 'vector' was not declared in this scope
    9 |     vector<bool>flag(n+1,true);
      |     ^~~~~~
a.cc:9:12: error: expected primary-expression before 'bool'
    9 |     vector<bool>flag(n+1,true);
      |            ^~~~
a.cc:10:12: error: expected primary-expression before 'bool'
   10 |     vector<bool>IsPrint(n+1,true);
      |            ^~~~
a.cc:11:12: error: 'pii' was not declared in this scope
   11 |     vector<pii>mp(n+1);
      |            ^~~
a.cc:11:16: error: 'mp' was not declared in this scope
   11 |     vector<pii>mp(n+1);
      |                ^~
a.cc:15:45: error: 'flag' was not declared in this scope
   15 |         if(temp==0){ans++; mp[i+1]=pii(0,0);flag[i+1]=false; continue;}
      |                                             ^~~~
a.cc:17:9: error: 'flag' was not declared in this scope
   17 |         flag[temp]=false;
      |         ^~~~
a.cc:4:13: error: expected primary-expression before 'long'
    4 | #define int long long
      |             ^~~~
a.cc:19:12: note: in expansion of macro 'int'
   19 |     vector<int>yebi;
      |            ^~~
a.cc:4:13: error: expected primary-expression before 'long'
    4 | #define int long long
      |             ^~~~
a.cc:20:12: note: in expansion of macro 'int'
   20 |     vector<int>dp(n+1,0);
      |            ^~~
a.cc:21:16: error: 'flag' was not declared in this scope
   21 |     rep(i,n)if(flag[i+1])yebi.push_back(i+1);
      |                ^~~~
a.cc:21:26: error: 'yebi' was not declared in this scope
   21 |     rep(i,n)if(flag[i+1])yebi.push_back(i+1);
      |                          ^~~~
a.cc:22:11: error: 'yebi' was not declared in this scope
   22 |     rep(z,yebi.size()){
      |           ^~~~
a.cc:2:33: note: in definition of macro 'rep'
    2 | #define rep(i,n) for(int i=0; i<n;i++)
      |                                 ^
a.cc:25:9: error: 'IsPrint' was not declared in this scope
   25 |         IsPrint[i]=false;
      |         ^~~~~~~
a.cc:26:9: error: 'flag' was not declared in this scope
   26 |         flag[i]=false;
      |         ^~~~
a.cc:27:12: error: expected ';' before 'next'
   27 |         pii next=mp[i];
      |            ^~~~~
      |            ;
a.cc:29:19: error: 'next' was not declared in this scope
   29 |             if(mp[next.first].second==0)break;
      |                   ^~~~
a.cc:30:24: error: 'next' was not declared in this scope
   30 |             if(IsPrint[next.first]==false){
      |                        ^~~~
a.cc:31:20: error: 'dp' was not declared in this scope
   31 |                 if(dp[next.first]>=k-1-i)break;
      |                    ^~
a.cc:32:17: error: 'dp' was not declared in this scope
   32 |                 dp[next.first]=max(dp[next.first],k-1-i);
      |                 ^~
a.cc:32:32: error: 'max' was not declared in this scope
   32 |                 dp[next.first]=max(dp[next.first],k-1-i);
      |                                ^~~
a.cc:37:21: error: 'next' was not declared in this scope
   37 |             IsPrint[next.first]=false;
      |                     ^~~~
a.cc:43:5: error: 'cout' was not declared in this scope
   43 |     cout<<ans<<endl;
      |     ^~~~
a.cc:43:16: error: 'endl' was not declared in this scope
   43 |     cout<<ans<<endl;
      |                ^~~~