Submission #528829

# Submission time Handle Problem Language Result Execution time Memory
528829 2022-02-21T14:26:25 Z Alex_tz307 Cat in a tree (BOI17_catinatree) C++17
100 / 100
144 ms 15452 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) {
  if (d <= mark[u]) {
    return;
  }
  mark[u] = d;
  for (int v : g[u]) {
    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 4 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 2 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 2 ms 4940 KB Output is correct
6 Correct 3 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 4888 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 2 ms 4940 KB Output is correct
13 Correct 2 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 2 ms 4940 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 3 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 4 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 2 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 2 ms 4940 KB Output is correct
6 Correct 3 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 4888 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 2 ms 4940 KB Output is correct
13 Correct 2 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 2 ms 4940 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 3 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 3 ms 4940 KB Output is correct
23 Correct 2 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 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 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 4988 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 4 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 2 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 2 ms 4940 KB Output is correct
6 Correct 3 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 4888 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 2 ms 4940 KB Output is correct
13 Correct 2 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 2 ms 4940 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 3 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 3 ms 4940 KB Output is correct
23 Correct 2 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 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 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 4988 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 59 ms 14120 KB Output is correct
42 Correct 33 ms 9812 KB Output is correct
43 Correct 40 ms 9708 KB Output is correct
44 Correct 37 ms 9824 KB Output is correct
45 Correct 36 ms 9808 KB Output is correct
46 Correct 94 ms 14504 KB Output is correct
47 Correct 144 ms 14532 KB Output is correct
48 Correct 85 ms 14548 KB Output is correct
49 Correct 83 ms 14544 KB Output is correct
50 Correct 27 ms 10184 KB Output is correct
51 Correct 28 ms 10168 KB Output is correct
52 Correct 28 ms 10196 KB Output is correct
53 Correct 57 ms 15424 KB Output is correct
54 Correct 62 ms 15452 KB Output is correct
55 Correct 65 ms 15428 KB Output is correct
56 Correct 3 ms 5068 KB Output is correct
57 Correct 7 ms 5964 KB Output is correct
58 Correct 26 ms 9932 KB Output is correct
59 Correct 73 ms 14788 KB Output is correct
60 Correct 61 ms 14212 KB Output is correct
61 Correct 83 ms 13916 KB Output is correct