Submission #821359

#TimeUsernameProblemLanguageResultExecution timeMemory
821359DenkataMarshmallow Molecules (CCO19_day2problem2)C++17
10 / 25
751 ms1048576 KiB
#include<bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("O3,unroll-loops") using namespace std; const int maxn = 1e5+3; long long i,j,p,q,n,m,k; long long ans; set <int> s[maxn]; set <int> Merge(set <int> a,set <int> b) { if(a.size()<b.size()) swap(a,b); if(b.empty()) return a; a.insert(b.begin(),b.end()); return a; } 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; s[p].insert(q); } for(i=1;i<=n;i++) { if(s[i].empty())continue; ans+=s[i].size(); p = *s[i].begin();s[i].erase(s[i].begin()); s[p] = Merge(s[i],s[p]); } 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...