QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#566971 | #9310. Permutation Counting 4 | Kidding_Ma | WA | 0ms | 3648kb | C++17 | 1.2kb | 2024-09-16 04:22:33 | 2024-09-16 04:22:33 |
Judging History
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 << "0\n";
return;
}
}
cout << "1\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3648kb
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:
0 0 0 0
result:
wrong answer 2nd words differ - expected: '1', found: '0'