QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#592142#9184. Team Codingchengning0909Compile Error//C++201.3kb2024-09-26 20:54:512024-09-26 20:54:53

Judging History

你现在查看的是最新测评结果

  • [2024-09-26 20:54:53]
  • 评测
  • [2024-09-26 20:54:51]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 10, M = 2010, B = 2000;

int n, k, a[N], dep[N], dfn[N], bk[N], tot;
vector<int> g[N], p[N], col[N];

void dfs(int u, int fa) {
    dfn[u] = bk[u] = ++tot;
    for (int v : g[u]) {
        if (v != fa) {
            dfs(v, u), bk[u] = max(bk[u], bk[v]);
        }
    }
}

void dfs1(int u, int fa) {
    dep[u] = dep[fa] + 1;
    for (int v : g[u]) {
        if (v != fa) {
            dfs1(v, u);
            if (p[u].size() < p[v].size()) swap(p[u], p[v]);
            for (int i = p[u].size() - 1, j = p[v].size() - 1; j >= 0; i--, j--) {
                p[u][i] += p[v][j];
            }
        }
    }
    p[u].push_back(1);

    if (col[a[u]].size() <= B) {
        vector<int> tmp = p[u];
        int cnt = 0;
        for (int x : col[a[u]]) {
            int k = dep[x] - dep[u];
            if (k >= 0 && tmp[tmp.size() - 1 - k]) tmp[tmp.size() - k - 1]--, cnt++;
        }
    }
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i], col[a[i]].push_back(i);
    }
    for (int i = 2, fa; i <= n; i++) {
        cin >> fa, fa++, g[fa].push_back(i);
    }
    dfs(1, 0), dfs1(1, 0);
    for (int i = 1; i <= k; i++) {
        if (cnt[i] > B)
    }
    return 0;
}

詳細信息

answer.code: In function ‘int main()’:
answer.code:53:13: error: ‘cnt’ was not declared in this scope; did you mean ‘int’?
   53 |         if (cnt[i] > B)
      |             ^~~
      |             int
answer.code:54:5: error: expected primary-expression before ‘}’ token
   54 |     }
      |     ^