Submission #940665

# Submission time Handle Problem Language Result Execution time Memory
940665 2024-03-07T12:53:00 Z phoenix0423 Cat in a tree (BOI17_catinatree) C++17
0 / 100
2 ms 6492 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define lowbit(x) x&-x
const int maxn = 2e5 + 5;
vector<int> adj[maxn];
int n, k;
int ans[maxn], d[maxn];

void dfs(int pos){
    ans[pos] = 1;
    for(auto x : adj[pos]){
        dfs(x);
        ans[pos] += ans[x];
        if(d[x] + d[pos] + 1 < k) ans[pos] --, d[pos] = max(d[pos], d[x] + 1);
        else d[pos] = min(d[pos], d[x] + 1);
    }
}

signed main(void){
    fastio;
    cin>>n>>k;
    for(int i = 1; i < n; i++){
        int x;
        cin>>x;
        adj[x].pb(i);
    }
    dfs(0);
    for(int i = 0; i < n; i++) cout<<ans[i]<<" "<<d[i]<<"\n";
    cout<<ans[0]<<"\n";
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 6492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 6492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 6492 KB Output isn't correct
2 Halted 0 ms 0 KB -