Submission #547780

# Submission time Handle Problem Language Result Execution time Memory
547780 2022-04-11T18:04:53 Z Soumya1 Cat in a tree (BOI17_catinatree) C++17
0 / 100
4 ms 5028 KB
#include <bits/stdc++.h>
#ifdef __LOCAL__
#include <debug_local.h>
#endif
using namespace std;
const int mxN = 2e5 + 5;
vector<int> ad[mxN];
pair<int, int> dp[mxN];
int n, d;
void dfs(int u, int p) {
  dp[u] = {0, 1e9};
  for (int v : ad[u]) {
    if (v == p) continue;
    dfs(v, u);
    auto [cnt, dd] = dp[v];
    if (dd + 1 + dp[u].second >= d) dp[u].first += cnt, dp[u].second = min(dp[u].second, dd + 1);
    else dp[u].first += cnt - 1;
  }
  if (dp[u].second >= d) dp[u].first++, dp[u].second = 0;
  // debug(u, dp[u]);
}
void testCase() {
  cin >> n >> d;
  for (int i = 1; i < n; i++) {
    int p;
    cin >> p;
    ad[p].push_back(i);
  }
  dfs(0, -1);
  cout << dp[0].first << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  testCase();
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 5028 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 4 ms 5020 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 5020 KB Output is correct
9 Correct 3 ms 5028 KB Output is correct
10 Incorrect 3 ms 4948 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 5028 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 4 ms 5020 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 5020 KB Output is correct
9 Correct 3 ms 5028 KB Output is correct
10 Incorrect 3 ms 4948 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 5028 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 4 ms 5020 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 5020 KB Output is correct
9 Correct 3 ms 5028 KB Output is correct
10 Incorrect 3 ms 4948 KB Output isn't correct
11 Halted 0 ms 0 KB -