QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#566969#9310. Permutation Counting 4Kidding_MaWA 0ms3536kbC++171.2kb2024-09-16 04:22:012024-09-16 04:22:01

Judging History

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

  • [2024-09-18 14:56:40]
  • hack成功,自动添加数据
  • (/hack/835)
  • [2024-09-18 14:41:06]
  • hack成功,自动添加数据
  • (/hack/831)
  • [2024-09-17 12:14:52]
  • hack成功,自动添加数据
  • (/hack/825)
  • [2024-09-16 04:22:01]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3536kb
  • [2024-09-16 04:22:01]
  • 提交

answer

#include "bits/stdc++.h"

using namespace std;
using i64 = int64_t;

struct UnionFind {
    int n;
    vector<int> f, sz;
    UnionFind(int n) : n(n), f(n), sz(n, 1) { 
        iota(f.begin(), f.end(), 0); 
    }
    int get(int x) {
        while (x != f[x]) {
            x = f[x] = f[f[x]];
        }
        return x;
    }
    bool unite(int x, int y) {
        x = get(x), y = get(y);
        if (x != y) {
            f[y] = x;
            sz[x] += sz[y];
            return 1;
        }
        return 0;
    }
    bool united(int x, int y) {
        return get(x) == get(y);
    }
    int size(int x) {
        x = get(x);
        return sz[x];
    }
};

void solve() {
    int n;
    cin >> n;
    vector<int> l(n), r(n);
    for (int i = 0; i < n; i++) {
        cin >> l[i] >> r[i];

        l[i]--;
    }

    UnionFind f(n + 1);
    for (int i = 0; i < n; i++) {
        if (f.unite(l[i], r[i])) {
            cout << "1\n";
            return;
        }
    }
    cout << "0\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

详细

Test #1:

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

input:

4
5
1 2
1 5
1 2
1 2
2 2
5
1 1
2 4
2 3
5 5
3 4
5
3 5
1 2
3 4
3 5
3 3
5
1 5
1 4
4 5
5 5
1 2

output:

1
1
1
1

result:

wrong answer 1st words differ - expected: '0', found: '1'