제출 #1360914

#제출 시각아이디문제언어결과실행 시간메모리
1360914ibshaCat in a tree (BOI17_catinatree)C++20
컴파일 에러
0 ms0 KiB
//#include <bits/stdc++.h>
#include <random>
#include "set"
#include <iostream>
#include "vector"
#include "deque"
#include "climits"
#include "algorithm"
#include "stack"
#include "map"
#include "unordered_set"
#include "bitset"
#include "unordered_map"

using namespace std;

/*
            ====================================================================================================
            #*###*############*####*#####*####*############*#########################################*##########
            %%%%%%%%%###%##*##=*+++=+++++++++++++*@#@%%###%%%%%%%%%%%%%%%%%%%%@%@@@%@@@@@@@@@@@@@%%%%%%%@@@%%%%#
            %%%%%%%%%%#####*##=*++++++++++++++++=*@%@%%###%%%%%%%%%%%%%%%%%%%%%%%%%%@@@%%@@@@@@@@%%%@@%%@@@%%%%#
            %%%%%%%%%######*##=*+++++++++++++++++*@%@%%###%%%%%%%%%%%%%%%%%%%%%%%%%%@@%%@@@@@@@@@%%#%%%%@@%#%#%#
            %%%%%%%%%%%####*##=*++++++++++++++++=+@%@%%###%@@@%%%%%%%%%%%%%%%%%%%%%%%@@%%%%@@@@@%%@%%%%%@%%%####
            %%%%%%%%%%####%*##=*++++++++++++++++=+@%@%%###%%%%%%%%%%%%%%%%%%%%%%%%%%%%@@@@@@@@@%@@@%%%%%@%######
            %%%%%%%%%%####%*##=*++++++++++++++===+@%@%%###%%%%%%%%%%%%%%%%%%%%%%%%%%%%@%%%@@@@%#@%%%%%%@%#######
            %%%%%%%%%%#####*##+++++++++++=++++=+++@%#%##%#######%%%%%%%%%%%%%%%%%%%%%%%%%%@@@@@@#%%%%%%@########
            %%%%%%%%%%#####*##+*+++++++++++++++==@%%%%%@##:-%=-=-+@%%%%%%%%%%%%%%%%%%%%%%%@@%%%@@@%%%%%@%%######
            %%%%%%%%%%#####*##+*++++++++++++=+*%%%%%%%%#%*.@:-%+-++%%%%%%%%%%%%%%%%%%%@%%%@%%%%%%%%%%%@@%#######
            %%%%%%%%%%####%*##=*=++++++++++++@%%%%%%%%%%%%#@@@@@@@=-@%%%%%%%%%%%%%%%%%%%%%@@%%%%%%%%%%@@@#######
            %%%%%%%%%%####%*##+*++++++++++++%@%%@%%%%%%%%#%@###*#%%@@%%%%%%%%%%%%%%%%%%%%%@@%%%%%%%%%%@@@%%%####
            %%%%%%%%%%####%*##+*+++++++++==@@%@@@@%%@%###%#@#=%@@@@@@@#=+@%%%%%%%%%%%%%%%%@@%%%%%%%%%%@@@%%%####
            %%%%%%%%%%####%*##*++++++++++++@@@@@@%#%%%%@#@@@@@@@@@@@@@@@@@-#%%%%%%%%%%%%%%@%%%%%%%%%%@@@%%%#####
            %%%%%%%%%#########=*++++++++++@@@@@%#@@@%%@@@@@@@@@@@@@@@@@@@@%@%%%%%%%%%%%%%%@%%%%%%%%%%%%%%%%#####
            %%%%%%%%######%*##=*++++++++++@%%@@@@@@@@@%%%####%@@%%%%@@@@@@@%#%%%%%%%%%%%%%@@%%%%%%%%%%%%%%%#####
            %%%%%%%%##########=*++++++***#%%@@@@@@%%##*++++++***#*++*#%@@@@%%%%%%%%%%%%%%%@@%%%%%%%%%%%%%%%%####
            %%%%%%%%######%###=*++++++#@%%@%@@@@%#*+++++====++++++++++*#@@@@%%%%%%%%%%%%%%@@%%%%%%%%%%%%%%%%%###
            %%%%%%%%######%###=*++++*%%%%@@@@@@@#+++++++=========++++++*#@@@@@%%%%%%%%%%%%@%%%%%%%%%%%%%%%%%####
            %%%%%%%%%#####%###=*++**%@#@@@@@@@@%+++=================++++*@@@@%%%%%%%%%%%%%@%%%%%%%%%%%%%%%%%%%##
            %%%%%%%%%#########=*+*#*@%@@@@@@%@%*++*+**##*++======*####*#*%@@@@%%%%%%%%%%%%@%%%%%%%%%%%%%%%%%%%%#
            %%%%%%%%%%########=#+*@%@@@@@@%@@@#*+=-=****#*+=+++=**#**#*+*#%@@%#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%###
            %%%%%%%%%%########+#*#@@@@%%%@@@%%#*+++*+=##+#*+*++##*+%**#**#%@@@@@%%%%%%%%%%@%%%%%%%%%%%%%%%%%%%##
            %%%%%%%%%%########=#**@@@@@@@@@@@@#*+=+=+++++++*==+*#*****++*#%%@@@%%%%%%%%%%%@%%%%%%%%%%%%%%%%%%%%#
            %%%%%%%%%#########=#**@@@@@@@@@@@@#*+===++++==+=+++**++=++++#%@@@@@%%%%%%%%%%%@%%%%%%%%%%%%%%%%%%%##
            %%%%%%%%%#####%###=##%@@@@@@@@@@@@#**+========++====++==+++*#%@@@@@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%##
            %%%%%%%#%#########+#+%@%#@@@@@@@@@%**+========+++===*++++++#%@@@%@%%%%%%%%@%%%%@%%%%%%%%%%%%%%%%####
            %%%%%%%%%%%#######=#+@@@@@@@@@@@@@#**++===+++****#**##*+++*%%@@@@@@%%%%@@@@@@@@@@@%%%%%%%%%%%%%%####
            @%%%%%##%%########+***@@@@@@@@@@@%#***++++*****#%###%%****#%@@@@%@%%%%%%%%%%%%%%%%%%%%%%%%#%%%%%%@@@
            %%%%%%%#%##%%%%###+**##%#@@@@@@@###***+++++++++++++*******#@@@@@@%%#%%%%%%%%%%%@%%%%%%%%%%%%%%%%%##%
            #@##%%##%##%######+**+++*@%##%%%%*********+++++++**********@@@@@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%##%
            %@##%#%%%####%####+#*+*+++++++++#%**************************#%#*#%%%%%%#%%%%%%%%%%%%%%%%%%%%%%%#%%%#
            @%%###%#%########*++===========++#@*++******##########******#++======@%%%%%%%%@%%%%%%%%%%%%%%%%%#%%#
            %%%##%##%##%###*++=========+=++++++*#********######*******+*=+==--=====*%%%#%%@%%%%%%%%%%%%%%%@%%%%#
            %%%##%%#%#####+++++*+=========+==+++**#******#####*******+*+++++==:======*%#%%@%%%%%%%%%%%%%%%%%%%#%
            %%%##%%%%#++==========--=----====+++++*##*****###*****+++#*===--+=====-------+**#@@%%%%%%%%%%%%%%%%%
            %#%%%+*++==========-=--=---------========++*@********+=%#===========----------======+@%%%%%%%%%%%%%%
            %#%***++========----------------------======++@.+++++*+==========---------------=-=====@%%%%%%%%%%%%
            %%**+++=========------------=---------=======+++*+*+%++========------------------==-====%%%%%%%%%%%%
            %**++++=========--===-=--=======------===========#*++============---------====----======+*%%%%%%%%%%
            #**+++++====+============+++++========-===========+*==============--=====+++++=====+===+=+*%%%%%%%%%
            #****+++==++++=====++++++****+++++===--=========+++++++=================+++***+++++++++++++%%%%%%%%%
            #*****+++++++++++++++++***##***++===-=---=======++*=*++++==============++++**#***+++++++++*+%%%%%%%%
            #******++++***++++++***######*+=====-----=--====++*+**+++======-=--=======+*#*##***+*+****#+@@%%%%%%
            ##********+**********####%%%+++++=====-----=====++*+***+++================++*#%####*********%@%+%%%%
            ###***************######%%#**++++++=============++++*#*+++======-========++++*%%####******#*%@@%%%%%
            ####****************##%%@#***++++++++++=========+++*=**++==============++++++**%%###*********#%%*%%%
            *****************+====*%%*********+++++===+====+++++++**++==+=*=====+++++++****@##++++=+****++*@%%%%
            *************+++=====--=@************+++++++++++++++******+++++++++++++++******#*+=====+++++*+++@%%%
            ***+++++*++++++=========+########**#%%*******++******%##***+++*++++++++++*******++++====++=++++**%%%
            ***+++========++========+%######*%###%#**************%###***************########***++++++++++++**#%%
            ***+++++++=====+++====+++*@#####%%%%%%######********#######**********###%%%%##%#**#*+++++==+++++**%%
            ***++++++++=======++++++**@%#######################%*#%%%#################%%#%%##**#*+++++++++++***%
            ***+++++**+++==========+*+#%%#######################**#%%###################%@%###*##*++++*+++++***%
            ****+**+++++++=======++*#*#@%%%%%%%%###########%%%#*****##%#%###########%%%%@%%%######+++++++++++***
            #*****+++++++++=====+++***#%%%%%%%%%%%%%%%%%%%%%%**++===+*#%%%%%%%%%%%%%%%%%@@%%#######*++++===+++**
            #*****+++++++=======+++**#%%%%%%%##############*+++==-===++*####%%%%%%##%%%%@@%%%######**+=====+++**
            ##****+++++++=====+*++***#%%%%%%%###########***++++++++++=++**############%%%%%%%%####****#*+=++++**
            ====================================================================================================
*/



using ll = long long;
using ull = unsigned long long;
#define MOD 1000000007
#define endl '\n'
#define pb(v,i) (v).push_back(i)
#define vll vector<ll>
#define pll pair<ll,ll>
#define _ << ' ' <<
#define clearvis for (int i=0; i<maxn;visited[i++]=false)
//__int128 fpow(ll base,ll exp){__int128 result=1;while (exp){if (exp%2==1) result*=base;exp/=2;base*=base;}return result;}
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
 */

ll fastpow(ll base, ll exp) {
    ll res = 1;
    while (exp) {
        if (exp & 1)
            res *= base;
        base *= base;
        res %= MOD;
        base %= MOD;
        exp >>= 1;
    }

    return res;
}

ll n, d;

vll edges[200005];
ll mnd[200005];
ll dpth[200005];
bool visited[200005];

vll leafs;
vll ansnodes;

void findleafdfs(ll u, ll p, ll d){
    bool wenttochild=false;
    dpth[u] = d;
    for (ll v : edges[u]){
        if (v == p) continue;
        wenttochild=true;
        findleafdfs(v,u, d+1);
    }

    if (!wenttochild) pb(leafs, u);
}

bool cmp(ll u, ll v){
    return dpth[u] < dpth[v];
}

queue<pll> bfsstack;

void bfs(pair<ll, ll> x){
    ll node = x.first, p = x.second, dist = mnd[node];
    if (visited[node]) return;
    visited[node] = true;


    for (auto nd : edges[node]){
        if (nd == p or visited[nd]) continue;
        mnd[nd] = max(mnd[nd], (dist ? dist-1 : d-1));
        bfsstack.push({nd, node});
    }

    if (dist == 0){
        pb(ansnodes, node);
    }
}

void solve() {
    // cout << fixed << setprecision(6);
    cin >> n >> d;
    for (int i=1; i<n; i++){
        ll x; cin >> x;
        pb(edges[i],x);
        pb(edges[x], i);
    }
    findleafdfs(0, 0, 0);
    if (edges[0].size()==1) pb(leafs, 0);
    // remove leafs that cant be chosen together, keep the deeper one

    sort(leafs.begin(), leafs.end(), cmp);
    ll i=0, j=1;
    while (j < leafs.size()){
        if (i == j) j++;
        if (j == leafs.size()) break;
        if (dpth[leafs[i]] + dpth[leafs[j]] < d){
            leafs[i] = INT_MAX;
            i++;
        }
        else j++;
    }
    sort(leafs.begin(), leafs.end());
    while (!leafs.empty() and *leafs.rbegin() == INT_MAX) leafs.pop_back();


    // leafs has all the valid leafs that can be chosen

    for (auto nd : leafs){
        bfsstack.push({nd, nd});
    }
    while (!bfsstack.empty()){
        pll x = bfsstack.front();
        bfsstack.pop();
        bfs(x);
    }
    cout << ansnodes.size();
}


signed main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    //freopen("berries.in","r",stdin);
    //freopen("berries.out","w",stdout);
    ll t=1;
    //cin >> t;
    for (int i=1; i<=t; i++){
        //cout << "Case #" << i << ": ";
        solve();
        cout << endl;
    }


    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

catinatree.cpp:140:1: error: 'queue' does not name a type
  140 | queue<pll> bfsstack;
      | ^~~~~
catinatree.cpp: In function 'void bfs(std::pair<long long int, long long int>)':
catinatree.cpp:151:9: error: 'bfsstack' was not declared in this scope
  151 |         bfsstack.push({nd, node});
      |         ^~~~~~~~
catinatree.cpp: In function 'void solve()':
catinatree.cpp:189:9: error: 'bfsstack' was not declared in this scope
  189 |         bfsstack.push({nd, nd});
      |         ^~~~~~~~
catinatree.cpp:191:13: error: 'bfsstack' was not declared in this scope
  191 |     while (!bfsstack.empty()){
      |             ^~~~~~~~