QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#364954#8130. Yet Another Balanced Coloring Problemchengning0909Compile Error//C++171.3kb2024-03-24 17:33:012024-03-24 17:33:02

Judging History

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

  • [2024-03-24 17:33:02]
  • 评测
  • [2024-03-24 17:33:01]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 10;

int T, n, m, c[N];
vector<int> g[2][N], e[N];

int dfs(int id, int u) {
    vector<int> p;
    for (int v : g[id][u]) {
        int k = dfs(id, v);
        if (k) p.push_back(k);
    }
    if (g[id][u].empty()) p.push_back(u);
    for (int i = 0; i < p.size(); i += 2) {
        e[p[i]].push_back(p[i + 1]);
        e[p[i + 1]].push_back(p[i]);
    }
    return p.size() % 2 ? p[p.size() - 1] : 0;
}

void DFS(int u, int col) {
    if (c[u] != -1) return ;
    c[u] = col;
    for (int v : e[u]) DFS(v, col ^ 1);
}

void Solve() {
    cin >> n >> m;
    for (int i = 1, fa; i < n; i++) {
        cin >> fa, g[0][fa].push_back(i);
    }
    for (int i = 1, fa; i < m; i++) {
        cin >> fa, g[1][fa].push_back(i);
    }
    dfs(0, n), dfs(1, m);
    int cnt = 0;
    for (int i = 1; i <= min(n, m) && g[0][i].empty() && g[1][i].empty(); i++, cnt++);
    fill(c + 1, c + cnt + 1, -1), DFS(1, 0);
    for (int i = 1; i <= cnt; i++) {
        cout << (c[i] ? 'B' : 'R'), e[i].clear();
    }
    cout << '\n';
    for (int i = 1; i < n; i++) g[0].clear();
    for (int i = 1; i < m; i++) g[1].clear();
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> T;
    while (T--) Solve();
    return 0;
}

Details

answer.code: In function ‘void Solve()’:
answer.code:46:38: error: request for member ‘clear’ in ‘g[0]’, which is of non-class type ‘std::vector<int> [100010]’
   46 |     for (int i = 1; i < n; i++) g[0].clear();
      |                                      ^~~~~
answer.code:47:38: error: request for member ‘clear’ in ‘g[1]’, which is of non-class type ‘std::vector<int> [100010]’
   47 |     for (int i = 1; i < m; i++) g[1].clear();
      |                                      ^~~~~