답안 #726963

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
726963 2023-04-19T17:37:40 Z grogu Cat in a tree (BOI17_catinatree) C++14
0 / 100
3 ms 4948 KB
#define here cerr<<"===========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include <bits/stdc++.h>
#define ld double
#define ll long long
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define all(a) a.begin(),a.end()
using namespace std;

#define maxn 200005
ll n,d;
vector<ll> g[maxn];
pll dfs(ll u,ll p){
    vector<ll> v; v.pb(0);
    for(ll s : g[u]){
        if(s==p) continue;
        pll cur = dfs(s,u);
        v.pb(cur.sc);
    }
    sort(all(v));
    reverse(all(v));
    while(v.size()>1&&v[v.size()-1] + v[v.size()-2]<d) v.popb();
    return {v.size(),v.back()+1};
}
void tc(){
	ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
    cin >> n >> d;
    for(ll i = 2;i<=n;i++){
        ll x; cin >> x;
        x++;
        g[x].pb(i);
        g[i].pb(x);
    }
    pll ans = dfs(1,1);
    cout<<ans.fi<<endl;
}

int main(){
	ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
	int t; t = 1;
	while(t--){
		tc();
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -