Submission #1092778

# Submission time Handle Problem Language Result Execution time Memory
1092778 2024-09-25T03:43:41 Z vjudge1 Team Coding (EGOI24_teamcoding) C++17
50 / 100
4000 ms 27000 KB
#include <iostream>
#include <vector>
#include <queue>

using namespace std;
using pii = pair<int, int>;

const int MAXN = 1e5 + 5, MAXL = 2000;

pii ans = {-1, MAXN};
vector<int> g[MAXN], a[MAXN], se[MAXN];
int n, k, tot, dfn[MAXN], b[MAXN], co[MAXN], dep[MAXN], cnt[MAXN];

void init(int u) {
  b[u] = dfn[u] = ++tot;
  for (auto v : g[u]) {
    dep[v] = dep[u] + 1;
    init(v), b[u] = b[v];
  }
}

void Max(int c, int k) {
  if (ans.first < c || (c == ans.first && ans.second > k)) {
    ans = {c, k};
  }
}

void dfs(int u) {
  for (auto v : g[u]) {
    dfs(v);
    if (a[u].size() < a[v].size()) {
      swap(a[u], a[v]);
    }
    for (int i = a[v].size() - 1, j = a[u].size() - 1; i >= 0; i--, j--) {
      a[u][j] += a[v][i];
    }
  }
  a[u].push_back(1);
  if (se[co[u]].size()) {
    int c = 0, k = 0;
    for (auto v : se[co[u]]) {
      int d = a[u].size() - 1 - (dep[v] - dep[u]);
      k += (dfn[v] >= dfn[u] && dfn[v] <= b[u]);
      if (d >= 0 && d < a[u].size() && cnt[d] < a[u][d]) {
        cnt[d]++, c++;
      }
    }
    Max(c, c - k);
    for (auto v : se[co[u]]) {
      int d = a[u].size() - 1 - (dep[v] - dep[u]);
      if (d >= 0 && d < a[u].size()) cnt[d] = 0;
    }
  }
}

void Dfs(int u, int co) {

}

int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> co[i], se[co[i]].push_back(i);
  }
  for (int i = 1, fa; i < n; i++) {
    cin >> fa, g[fa].push_back(i);
  }
  init(0), dfs(0);
  for (int i = 1; i <= k; i++) {
    if (se[i].size() > MAXL) {

    }
  }
  cout << ans.first << ' ' << ans.second;
  return 0;
}

Compilation message

Main.cpp: In function 'void dfs(int)':
Main.cpp:44:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |       if (d >= 0 && d < a[u].size() && cnt[d] < a[u][d]) {
      |                     ~~^~~~~~~~~~~~~
Main.cpp:51:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |       if (d >= 0 && d < a[u].size()) cnt[d] = 0;
      |                     ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7516 KB Output is correct
2 Correct 3 ms 7516 KB Output is correct
3 Correct 5 ms 7516 KB Output is correct
4 Correct 3 ms 7516 KB Output is correct
5 Correct 3 ms 7476 KB Output is correct
6 Correct 3 ms 7516 KB Output is correct
7 Correct 4 ms 7440 KB Output is correct
8 Correct 4 ms 7772 KB Output is correct
9 Correct 37 ms 26320 KB Output is correct
10 Correct 3 ms 7516 KB Output is correct
11 Correct 9 ms 7876 KB Output is correct
12 Execution timed out 4067 ms 24664 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7516 KB Output is correct
2 Correct 3 ms 7516 KB Output is correct
3 Correct 3 ms 7516 KB Output is correct
4 Correct 8 ms 7768 KB Output is correct
5 Execution timed out 4080 ms 24784 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7512 KB Output is correct
2 Correct 3 ms 7516 KB Output is correct
3 Correct 3 ms 7516 KB Output is correct
4 Correct 3 ms 7516 KB Output is correct
5 Correct 3 ms 7516 KB Output is correct
6 Correct 3 ms 7516 KB Output is correct
7 Correct 3 ms 7304 KB Output is correct
8 Correct 35 ms 26664 KB Output is correct
9 Correct 3 ms 7516 KB Output is correct
10 Correct 3 ms 7768 KB Output is correct
11 Correct 35 ms 27000 KB Output is correct
12 Correct 3 ms 7508 KB Output is correct
13 Correct 3 ms 7516 KB Output is correct
14 Correct 3 ms 7516 KB Output is correct
15 Correct 3 ms 7528 KB Output is correct
16 Correct 3 ms 7516 KB Output is correct
17 Correct 4 ms 7516 KB Output is correct
18 Correct 48 ms 15188 KB Output is correct
19 Correct 54 ms 14932 KB Output is correct
20 Correct 54 ms 16740 KB Output is correct
21 Correct 53 ms 14356 KB Output is correct
22 Correct 46 ms 15440 KB Output is correct
23 Correct 41 ms 21068 KB Output is correct
24 Correct 43 ms 18768 KB Output is correct
25 Correct 4 ms 7516 KB Output is correct
26 Correct 3 ms 7688 KB Output is correct
27 Correct 4 ms 7768 KB Output is correct
28 Correct 5 ms 7524 KB Output is correct
29 Correct 6 ms 8284 KB Output is correct
30 Correct 46 ms 14760 KB Output is correct
31 Correct 48 ms 15440 KB Output is correct
32 Correct 48 ms 17772 KB Output is correct
33 Correct 43 ms 15196 KB Output is correct
34 Correct 3 ms 7516 KB Output is correct
35 Correct 3 ms 7516 KB Output is correct
36 Correct 3 ms 7516 KB Output is correct
37 Correct 3 ms 7460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7516 KB Output is correct
2 Correct 3 ms 7516 KB Output is correct
3 Correct 3 ms 7516 KB Output is correct
4 Correct 3 ms 7516 KB Output is correct
5 Correct 3 ms 7516 KB Output is correct
6 Correct 3 ms 7516 KB Output is correct
7 Correct 3 ms 7516 KB Output is correct
8 Correct 4 ms 7768 KB Output is correct
9 Correct 3 ms 7516 KB Output is correct
10 Correct 7 ms 7880 KB Output is correct
11 Correct 3 ms 7516 KB Output is correct
12 Correct 3 ms 7872 KB Output is correct
13 Correct 3 ms 7516 KB Output is correct
14 Correct 15 ms 7636 KB Output is correct
15 Correct 3 ms 7516 KB Output is correct
16 Correct 10 ms 7560 KB Output is correct
17 Correct 3 ms 7520 KB Output is correct
18 Correct 4 ms 7512 KB Output is correct
19 Correct 3 ms 7520 KB Output is correct
20 Correct 28 ms 7632 KB Output is correct
21 Correct 3 ms 7520 KB Output is correct
22 Correct 3 ms 7520 KB Output is correct
23 Correct 6 ms 7520 KB Output is correct
24 Correct 3 ms 7520 KB Output is correct
25 Correct 4 ms 7516 KB Output is correct
26 Correct 3 ms 7520 KB Output is correct
27 Correct 3 ms 7716 KB Output is correct
28 Correct 4 ms 7776 KB Output is correct
29 Correct 3 ms 7524 KB Output is correct
30 Correct 7 ms 7788 KB Output is correct
31 Correct 4 ms 7528 KB Output is correct
32 Correct 15 ms 7516 KB Output is correct
33 Correct 3 ms 7672 KB Output is correct
34 Correct 6 ms 7532 KB Output is correct
35 Correct 5 ms 7516 KB Output is correct
36 Correct 6 ms 7516 KB Output is correct
37 Correct 22 ms 7616 KB Output is correct
38 Correct 3 ms 7516 KB Output is correct
39 Correct 3 ms 7516 KB Output is correct
40 Correct 3 ms 7516 KB Output is correct
41 Correct 3 ms 7516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7516 KB Output is correct
2 Correct 3 ms 7516 KB Output is correct
3 Correct 5 ms 7516 KB Output is correct
4 Correct 3 ms 7516 KB Output is correct
5 Correct 3 ms 7476 KB Output is correct
6 Correct 3 ms 7516 KB Output is correct
7 Correct 4 ms 7440 KB Output is correct
8 Correct 4 ms 7772 KB Output is correct
9 Correct 37 ms 26320 KB Output is correct
10 Correct 3 ms 7516 KB Output is correct
11 Correct 9 ms 7876 KB Output is correct
12 Execution timed out 4067 ms 24664 KB Time limit exceeded
13 Halted 0 ms 0 KB -