답안 #730393

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
730393 2023-04-25T19:47:42 Z USER Cat in a tree (BOI17_catinatree) C++14
0 / 100
2 ms 4996 KB
#include <bits/stdc++.h>
using namespace std;

int n, k, lvl[200001];
vector <int> g[200001];

pair <int, int> dfs(int nod = 0, int height = 0) {

    lvl[nod] = height;
    vector <pair<int, int>> v;
    int ret = 1;
    v.push_back({height, nod});

    for (auto &i : g[nod]) {

        pair <int, int> aux = dfs(i, height + 1);
        v.push_back({lvl[aux.first], aux.first});
        ret += aux.second;
    }

    sort(v.begin(), v.end());

    int i = 0;
    while (v.size() - i > 1 && v[i].first + v[i + 1].first < k)
        i++, ret--;

    return {v[i].second, ret};
}

int main() {

    cin >> n >> k;

    for (int i = 1; i < n; i++) {

        int x;
        cin >> x;

        g[x].push_back(i);
    }

    cout << dfs().second;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4996 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4996 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4996 KB Output isn't correct
2 Halted 0 ms 0 KB -