Submission #528836

# Submission time Handle Problem Language Result Execution time Memory
528836 2022-02-21T14:43:09 Z Alex_tz307 Cat in a tree (BOI17_catinatree) C++17
100 / 100
166 ms 15464 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;
  d -= 1;
  if (d) {
    for (int v : g[u]) {
      if (mark[v] < d) {
        dfs(v, d);
      }
    }
  }
}

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 3 ms 4940 KB Output is correct
2 Correct 2 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 3 ms 4940 KB Output is correct
6 Correct 2 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 4 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 5004 KB Output is correct
18 Correct 2 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 2 ms 4940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 2 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 3 ms 4940 KB Output is correct
6 Correct 2 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 4 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 5004 KB Output is correct
18 Correct 2 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 2 ms 4940 KB Output is correct
21 Correct 3 ms 5068 KB Output is correct
22 Correct 4 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 4 ms 5048 KB Output is correct
26 Correct 5 ms 4940 KB Output is correct
27 Correct 3 ms 4940 KB Output is correct
28 Correct 3 ms 5068 KB Output is correct
29 Correct 4 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 4 ms 5068 KB Output is correct
40 Correct 3 ms 5068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 2 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 3 ms 4940 KB Output is correct
6 Correct 2 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 4 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 5004 KB Output is correct
18 Correct 2 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 2 ms 4940 KB Output is correct
21 Correct 3 ms 5068 KB Output is correct
22 Correct 4 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 4 ms 5048 KB Output is correct
26 Correct 5 ms 4940 KB Output is correct
27 Correct 3 ms 4940 KB Output is correct
28 Correct 3 ms 5068 KB Output is correct
29 Correct 4 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 4 ms 5068 KB Output is correct
40 Correct 3 ms 5068 KB Output is correct
41 Correct 58 ms 14036 KB Output is correct
42 Correct 44 ms 9772 KB Output is correct
43 Correct 43 ms 9820 KB Output is correct
44 Correct 38 ms 9832 KB Output is correct
45 Correct 37 ms 9924 KB Output is correct
46 Correct 80 ms 14532 KB Output is correct
47 Correct 166 ms 14624 KB Output is correct
48 Correct 106 ms 14524 KB Output is correct
49 Correct 100 ms 14532 KB Output is correct
50 Correct 25 ms 10240 KB Output is correct
51 Correct 28 ms 10268 KB Output is correct
52 Correct 28 ms 10252 KB Output is correct
53 Correct 56 ms 15464 KB Output is correct
54 Correct 59 ms 15428 KB Output is correct
55 Correct 68 ms 15444 KB Output is correct
56 Correct 3 ms 5068 KB Output is correct
57 Correct 7 ms 6092 KB Output is correct
58 Correct 26 ms 10108 KB Output is correct
59 Correct 70 ms 14900 KB Output is correct
60 Correct 60 ms 14292 KB Output is correct
61 Correct 80 ms 13880 KB Output is correct