QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#585318#9319. Bull Farmsha7dowCompile Error//C++142.8kb2024-09-23 20:19:532024-09-23 20:19:53

Judging History

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

  • [2024-09-23 20:19:53]
  • 评测
  • [2024-09-23 20:19:53]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define fi first
#define se second

using ll = long long;
using VI = vector<int>;
using PII = pair<int, int>;
using VPII = vector<PII>;

const int inf = 1 << 30;

void solve() {
    int n, l, m;
    cin >> n >> l >> m;
    VI ans(m + 2), fa(n + 2), to(n + 2), cnt(n + 2);
    vector<VPII> e(n + 2); 

    function<int(int)> find = [&](int x) {
        return fa[x] == x ? x : fa[x] = find(fa[x]);
    };
    for (int i = 1; i <= n; i++) {
        fa[i] = i;
    }
    
    for (int i = 1; i <= l; i++) {
        string s;
        cin >> s;
        for (int j = 1, k = 0; j <= n; k += 2, j++) {
            to[j] = (s[k] - 48) * 50 + (s[k + 1] - 48);
        }
        for (int j = 0; j <= n; j++) {
            cnt[j] = 0;
        }
        for (int j = 1; j <= n; j++) {
            cnt[0] += !cnt[to[j]]++;
        }
        if (cnt[0] == n) {
            for (int j = 1; j <= n; j++) {
                int u = find(j), v = find(to[j]);
                if (u != v) {
                    fa[v] = u;
                    e[u].pb({v, i});
                    e[v].pb({u, i});
                }
            }
        } else if (cnt[0] == n - 1) {
            int s, t;
            for (int j = 1; j <= n; j++) {
                if (!cnt[j]) {
                    t = j;
                } else if (cnt[j] == 2) {
                    s = j;
                }
            }
            for (int j = 1; j <= n; j++) {
                if (to[j] == s) {
                    e[j].pb({t, i});
                }
            }
        }
    }

    vector<queue<int>> q(l + 2);
    vector dis(n + 2, VI(n + 2, inf));
    VI vis(n + 2);
    for (int i = 1; i <= n; i++) {
        dis[i][i] = 0;
        q[0].push(i);
        fill(vis.begin(), vis.end(), 0);
        for (int j = 0; j <= l; j++) {
            while (!q[j].empty()) {
                int x = q[j].front();
                q[j].pop();
                if (vis[x]) continue;
                vis[x] = 1;
                for (auto [y, w]: e[x]) {
                    w = max(w, dis[i][x]);
                    if (w < dis[i][y]) {
                        dis[i][y] = w;
                        q[w].push(y);
                    }
                }
            }
        }
    }

    for (int i = 1; i <= m; i++) {
        string s;
        cin >> s;
        int u = (s[0] - 48) * 50 + (s[1] - 48);
        int v = (s[2] - 48) * 50 + (s[3] - 48);
        int w = (s[4] - 48) * 50 + (s[5] - 48);
        cout << "01"[dis[u][v] <= w];
    }
    cout << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int tc = 1;
    cin >> tc;
    while (tc--) {
        solve();
    }
    return 0;
}

詳細信息

answer.code: In function ‘void solve()’:
answer.code:67:12: error: missing template arguments before ‘dis’
   67 |     vector dis(n + 2, VI(n + 2, inf));
      |            ^~~
answer.code:70:9: error: ‘dis’ was not declared in this scope; did you mean ‘vis’?
   70 |         dis[i][i] = 0;
      |         ^~~
      |         vis
answer.code:79:27: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   79 |                 for (auto [y, w]: e[x]) {
      |                           ^
answer.code:96:22: error: ‘dis’ was not declared in this scope; did you mean ‘vis’?
   96 |         cout << "01"[dis[u][v] <= w];
      |                      ^~~
      |                      vis