QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#585383#9319. Bull Farmsha7dowWA 0ms3536kbC++172.8kb2024-09-23 20:34:582024-09-23 20:34:58

Judging History

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

  • [2024-09-23 20:34:58]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3536kb
  • [2024-09-23 20:34:58]
  • 提交

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});
                }
            }
        } 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;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3536kb

input:

2
5 2 4
0305040201
0404040404
030300
020500
050102
020501
6 2 4
030603010601
010203060504
030202
060402
050602
060401

output:

1001
0000

result:

wrong answer 1st lines differ - expected: '1011', found: '1001'