#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz size
const int mxN = 1e5;
int p[mxN][2];
int ssize[mxN][2];
int gpar(int c, int w){
if (p[c][w] == c) return c;
p[c][w] = gpar(p[c][w],w);
return p[c][w];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m;
cin >> n >> m;
for (int i = 0; i < n; i++) for (int j = 0; j < 2; j++) {p[i][j] = i; ssize[i][j] = 1;}
int a,b;
int x,y;
int cnt = 0;
for (int i = 0; i < m; i++){
cin >> a >> b;
a -= 1;
b -= 1;
x = gpar(a,0);
y = gpar(b,0);
if (x != y){
//adj[a].pb(b);
// adj[b].pb(a);
cnt++;
if (ssize[x][0] < ssize[y][0]) swap(x,y);
ssize[x][0] += ssize[y][0];
p[y][0] = x;
continue;
}
x = gpar(a,1);
y = gpar(b,1);
if (x == y) continue;
if (ssize[x][1] < ssize[y][1]) swap(x,y);
ssize[x][1] += ssize[y][1];
p[y][1] = x;
//adj[a].pb(b);
// adj[b].pb(a);
cnt++;
}
if (cnt > 2*n-2) while(true) continue;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
604 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
5972 KB |
Output is correct |
2 |
Incorrect |
54 ms |
5620 KB |
Wrong number of edges |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
10068 KB |
Output is correct |
2 |
Incorrect |
112 ms |
11856 KB |
Wrong number of edges |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
157 ms |
16812 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
209 ms |
22096 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
329 ms |
34644 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
430 ms |
45640 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
547 ms |
57172 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
681 ms |
65536 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |