Submission #821452

#TimeUsernameProblemLanguageResultExecution timeMemory
821452DenkataMarshmallow Molecules (CCO19_day2problem2)C++14
25 / 25
87 ms24480 KiB
#include<bits/stdc++.h> using namespace std; const int maxn = 1e5+3; int i,j,p,q,n,m,k; long long ans; set <int> s[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>n>>m; for(i=1;i<=m;i++) { cin>>p>>q; if(p>q) swap(p,q); s[p].insert(q); } for(i=1;i<=n;i++) { if(s[i].size()==0)continue; ans+=(long long)s[i].size(); p = *s[i].begin();s[i].erase(p); if(s[p].size()<s[i].size()) swap(s[i],s[p]); for(auto j:s[i]) s[p].insert(j); } cout<<ans<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...