Submission #530007

# Submission time Handle Problem Language Result Execution time Memory
530007 2022-02-24T11:21:46 Z Alex_tz307 Cat in a tree (BOI17_catinatree) C++17
100 / 100
155 ms 16248 KB
#include <bits/stdc++.h>

using namespace std;

const int kN = 2e5;
vector<int> g[kN];
int dep[kN], mark[kN];
bitset<kN> done;

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

void testCase() {
  int n, d;
  cin >> n >> d;
  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, last = -1;
  for (auto it : nodes) {
    if (last != -1 && last < it.first) {
      done[last] = true;
    }
    if (mark[it.second] == 0) {
      ans += 1;
      dfs(it.second, d);
    }
    last = it.first;
  }
  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 4 ms 5020 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 4984 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 2 ms 5016 KB Output is correct
8 Correct 3 ms 5020 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 5024 KB Output is correct
11 Correct 2 ms 5012 KB Output is correct
12 Correct 3 ms 5016 KB Output is correct
13 Correct 3 ms 5012 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 5016 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 4 ms 5016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 4 ms 5020 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 4984 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 2 ms 5016 KB Output is correct
8 Correct 3 ms 5020 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 5024 KB Output is correct
11 Correct 2 ms 5012 KB Output is correct
12 Correct 3 ms 5016 KB Output is correct
13 Correct 3 ms 5012 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 5016 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 4 ms 5016 KB Output is correct
21 Correct 3 ms 5068 KB Output is correct
22 Correct 3 ms 5008 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 5020 KB Output is correct
26 Correct 3 ms 4992 KB Output is correct
27 Correct 3 ms 5068 KB Output is correct
28 Correct 3 ms 5016 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 4 ms 5012 KB Output is correct
35 Correct 4 ms 5020 KB Output is correct
36 Correct 5 ms 5068 KB Output is correct
37 Correct 4 ms 5068 KB Output is correct
38 Correct 4 ms 5016 KB Output is correct
39 Correct 3 ms 5016 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 4 ms 5020 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 4984 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 2 ms 5016 KB Output is correct
8 Correct 3 ms 5020 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 5024 KB Output is correct
11 Correct 2 ms 5012 KB Output is correct
12 Correct 3 ms 5016 KB Output is correct
13 Correct 3 ms 5012 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 5016 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 4 ms 5016 KB Output is correct
21 Correct 3 ms 5068 KB Output is correct
22 Correct 3 ms 5008 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 5020 KB Output is correct
26 Correct 3 ms 4992 KB Output is correct
27 Correct 3 ms 5068 KB Output is correct
28 Correct 3 ms 5016 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 4 ms 5012 KB Output is correct
35 Correct 4 ms 5020 KB Output is correct
36 Correct 5 ms 5068 KB Output is correct
37 Correct 4 ms 5068 KB Output is correct
38 Correct 4 ms 5016 KB Output is correct
39 Correct 3 ms 5016 KB Output is correct
40 Correct 3 ms 5068 KB Output is correct
41 Correct 59 ms 15028 KB Output is correct
42 Correct 32 ms 10344 KB Output is correct
43 Correct 42 ms 10268 KB Output is correct
44 Correct 36 ms 10308 KB Output is correct
45 Correct 54 ms 10360 KB Output is correct
46 Correct 90 ms 15772 KB Output is correct
47 Correct 155 ms 15724 KB Output is correct
48 Correct 100 ms 15676 KB Output is correct
49 Correct 105 ms 15692 KB Output is correct
50 Correct 28 ms 10588 KB Output is correct
51 Correct 30 ms 10648 KB Output is correct
52 Correct 31 ms 10600 KB Output is correct
53 Correct 58 ms 16156 KB Output is correct
54 Correct 63 ms 16212 KB Output is correct
55 Correct 67 ms 16124 KB Output is correct
56 Correct 3 ms 5072 KB Output is correct
57 Correct 7 ms 6172 KB Output is correct
58 Correct 26 ms 10812 KB Output is correct
59 Correct 74 ms 16248 KB Output is correct
60 Correct 64 ms 15368 KB Output is correct
61 Correct 89 ms 15056 KB Output is correct