Submission #903862

#TimeUsernameProblemLanguageResultExecution timeMemory
903862adaawfMarshmallow Molecules (CCO19_day2problem2)C++14
25 / 25
83 ms11400 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...