Submission #606740

# Submission time Handle Problem Language Result Execution time Memory
606740 2022-07-26T08:01:33 Z socpite Cat in a tree (BOI17_catinatree) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;

#define f first
#define s second

typedef long long ll;

const int maxn = 105;
const int mod = 1e9+7;

int d[maxn];
vector<int> tree[maxn];
int n, D;

stack<int> q;

void dfs(int x, int p, int dep){
    d[x]=-1;
    for(auto v: tree[x]){
        if(v==p)continue;
        if(!dep){
            d[v]--;
            if(d[v] <= 1)q.push(v);
        }
        else dfs(v, x, dep-1);
    }
}

int main(){
    cin >> n >> D;
    for(int i = 1; i < n; i++){
        int x;
        cin >> x;
        tree[x].push_back(i);
        tree[i].push_back(x);
        d[x]++;
        d[i]++;
    }
    for(int i = 0; i < n; i++)if(d[i]==1){
        q.push(i);
    }
    int ans= 0;
    while(!q.empty()){
        auto x = q.front();
        q.pop();
        if(d[x] < 0)continue;
        ans++;
        dfs(x, -1, D-1);
    }
    cout << ans;
}


Compilation message

catinatree.cpp: In function 'int main()':
catinatree.cpp:46:20: error: 'class std::stack<int>' has no member named 'front'
   46 |         auto x = q.front();
      |                    ^~~~~