Submission #528831

# Submission time Handle Problem Language Result Execution time Memory
528831 2022-02-21T14:29:49 Z Alex_tz307 Cat in a tree (BOI17_catinatree) C++17
100 / 100
136 ms 15448 KB
#include <bits/stdc++.h>

using namespace std;

const int kN = 2e5;
vector<int> g[kN];
int mark[kN];

void dfs(int u, int d) {
  mark[u] = d;
  if (d > 1) {
    for (int v : g[u]) {
      if (mark[v] < d - 1) {
        dfs(v, d - 1);
      }
    }
  }
}

void testCase() {
  int n, d;
  cin >> n >> d;
  vector<int> dep(n);
  vector<pair<int, int>> nodes(n, {0, 0});
  for (int v = 1; v < n; ++v) {
    int u;
    cin >> u;
    g[u].emplace_back(v);
    g[v].emplace_back(u);
    dep[v] = dep[u] + 1;
    nodes[v] = {dep[v], v};
  }
  sort(nodes.begin(), nodes.end(), greater<pair<int, int>>());
  int ans = 0;
  for (auto it : nodes) {
    if (mark[it.second] == 0) {
      ans += 1;
      dfs(it.second, d);
    }
  }
  cout << ans << '\n';
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int tests = 1;
  for (int tc = 0; tc < tests; ++tc) {
    testCase();
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 2 ms 4940 KB Output is correct
5 Correct 4 ms 4992 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 2 ms 4940 KB Output is correct
10 Correct 2 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 2 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 2 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 2 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 2 ms 4940 KB Output is correct
5 Correct 4 ms 4992 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 2 ms 4940 KB Output is correct
10 Correct 2 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 2 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 2 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 2 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 5068 KB Output is correct
22 Correct 2 ms 4940 KB Output is correct
23 Correct 3 ms 4940 KB Output is correct
24 Correct 3 ms 4940 KB Output is correct
25 Correct 3 ms 4940 KB Output is correct
26 Correct 3 ms 5068 KB Output is correct
27 Correct 3 ms 4940 KB Output is correct
28 Correct 3 ms 5068 KB Output is correct
29 Correct 3 ms 5068 KB Output is correct
30 Correct 3 ms 5068 KB Output is correct
31 Correct 3 ms 5068 KB Output is correct
32 Correct 3 ms 5068 KB Output is correct
33 Correct 3 ms 5068 KB Output is correct
34 Correct 3 ms 5068 KB Output is correct
35 Correct 3 ms 5068 KB Output is correct
36 Correct 3 ms 5068 KB Output is correct
37 Correct 3 ms 5068 KB Output is correct
38 Correct 3 ms 5068 KB Output is correct
39 Correct 3 ms 5068 KB Output is correct
40 Correct 3 ms 5068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 2 ms 4940 KB Output is correct
5 Correct 4 ms 4992 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 2 ms 4940 KB Output is correct
10 Correct 2 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 2 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 2 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 2 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 5068 KB Output is correct
22 Correct 2 ms 4940 KB Output is correct
23 Correct 3 ms 4940 KB Output is correct
24 Correct 3 ms 4940 KB Output is correct
25 Correct 3 ms 4940 KB Output is correct
26 Correct 3 ms 5068 KB Output is correct
27 Correct 3 ms 4940 KB Output is correct
28 Correct 3 ms 5068 KB Output is correct
29 Correct 3 ms 5068 KB Output is correct
30 Correct 3 ms 5068 KB Output is correct
31 Correct 3 ms 5068 KB Output is correct
32 Correct 3 ms 5068 KB Output is correct
33 Correct 3 ms 5068 KB Output is correct
34 Correct 3 ms 5068 KB Output is correct
35 Correct 3 ms 5068 KB Output is correct
36 Correct 3 ms 5068 KB Output is correct
37 Correct 3 ms 5068 KB Output is correct
38 Correct 3 ms 5068 KB Output is correct
39 Correct 3 ms 5068 KB Output is correct
40 Correct 3 ms 5068 KB Output is correct
41 Correct 57 ms 14080 KB Output is correct
42 Correct 37 ms 9796 KB Output is correct
43 Correct 40 ms 9824 KB Output is correct
44 Correct 35 ms 9768 KB Output is correct
45 Correct 37 ms 9816 KB Output is correct
46 Correct 82 ms 14532 KB Output is correct
47 Correct 136 ms 14500 KB Output is correct
48 Correct 88 ms 14556 KB Output is correct
49 Correct 90 ms 14660 KB Output is correct
50 Correct 25 ms 10180 KB Output is correct
51 Correct 28 ms 10200 KB Output is correct
52 Correct 29 ms 10260 KB Output is correct
53 Correct 51 ms 15440 KB Output is correct
54 Correct 57 ms 15340 KB Output is correct
55 Correct 57 ms 15448 KB Output is correct
56 Correct 3 ms 5068 KB Output is correct
57 Correct 7 ms 6008 KB Output is correct
58 Correct 25 ms 10104 KB Output is correct
59 Correct 73 ms 14924 KB Output is correct
60 Correct 60 ms 14208 KB Output is correct
61 Correct 79 ms 13972 KB Output is correct