QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#719852 | #6765. Don't Really Like How The Story Ends | 333zhan | WA | 56ms | 3612kb | C++20 | 831b | 2024-11-07 09:23:53 | 2024-11-07 09:23:53 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
struct DSU {
vector <int> f;
DSU (int n) {
f.resize (n + 1);
iota (f.begin (), f.end (), 0);
}
int find (int x) {
return f[x] = f[x] == x ? x : find (f[x]);
}
void merge (int x, int y) {
x = find (x);
y = find (y);
f[x] = y;
}
};
void solve () {
int n, m;
cin >> n >> m;
DSU dsu (n);
for (int i = 0; i < m; i ++) {
int x, y;
cin >> x >> y;
x --; y --;
dsu.merge(x, y);
}
int sum = -1;
for (int i = 0; i < n; i ++) {
if (dsu.find (i) == i) {
sum ++;
}
}
cout << sum << '\n';
}
signed main () {
ios::sync_with_stdio (false);
cin.tie (nullptr);
int T = 1;
cin >> T;
while (T --) {
solve ();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3544kb
input:
3 2 3 1 1 1 2 2 1 4 1 1 4 4 2 1 2 3 4
output:
0 2 1
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 56ms
memory: 3612kb
input:
117747 3 7 2 1 3 3 1 3 1 1 3 2 1 1 3 1 4 8 2 3 4 3 3 2 4 2 1 3 2 1 4 3 2 4 3 4 2 3 2 2 3 3 1 1 2 5 1 1 2 2 2 2 1 2 2 2 3 7 2 1 1 2 3 3 3 2 1 2 3 3 3 2 4 5 1 2 3 3 4 4 1 4 2 1 3 1 3 2 1 3 1 1 1 1 1 1 1 6 1 1 1 1 1 1 1 1 1 1 1 1 5 4 2 1 2 5 1 3 3 2 4 7 1 1 2 4 3 2 1 1 1 1 4 2 2 3 5 8 3 3 2 2 4 2 1 4 1...
output:
0 0 1 0 0 1 1 0 0 1 1 0 0 0 1 0 2 0 1 0 0 3 0 0 0 2 0 1 1 0 0 0 0 0 1 1 3 0 1 0 3 0 2 0 0 0 1 2 0 1 0 0 0 0 0 2 0 0 0 1 0 0 0 0 0 0 1 0 0 2 2 0 0 0 1 0 1 3 0 0 0 1 1 0 0 0 1 2 0 1 1 0 0 0 0 0 0 3 0 0 2 0 0 0 1 0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 1 0 1 2 0 0 0 0 1 0 0 0 0 1 0 0 0 ...
result:
wrong answer 12th lines differ - expected: '1', found: '0'