This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2")
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz size
const int mxN = 1e5;
int n,m;
int p[2*mxN];
int gpar(const int &c){
if (p[c] == c) return c;
p[c] = gpar(p[c]);
return p[c];
}
bool ss(const int &a, const int &b){
return gpar(a) == gpar(b);
}
void un(const int &a, const int &b){
p[gpar(a)] = gpar(b);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for (int i = 0; i < 2*n; i++) p[i] = i;
int a,b;
int cnt = 0;
for (int i = 0; i < m; i++){
cin >> a >> b;
a -= 1;
b -= 1;
if (!ss(a,b)) un(a,b);
else if (!ss(a+n,b+n)) un(a+n,b+n);
else continue;
cnt++;
}
if (cnt > 2*n-2) while(true) continue;
cout << cnt << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |