This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <set>
using namespace std;
set<int> s[100005];
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
long long int n, m, c = 0;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int u, v;
cin >> u >> v;
if (u > v) swap(u, v);
s[u].insert(v);
}
for (int i = 1; i <= n; i++) {
if (s[i].empty()) continue;
c += s[i].size();
int h = *s[i].begin();
s[i].erase(s[i].begin());
if (s[i].size() > s[h].size()) s[h].swap(s[i]);
for (int w : s[i]) s[h].insert(w);
s[i].clear();
}
cout << c;
}
# | 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... |