Submission #821393

# Submission time Handle Problem Language Result Execution time Memory
821393 2023-08-11T09:48:13 Z Denkata Marshmallow Molecules (CCO19_day2problem2) C++14
0 / 25
44 ms 15516 KB
#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];
set <int> Merge(set <int> a,set <int> b)
{
    if(b.empty())
        return a;
    if(a.empty())
        return b;
    if((int)a.size()<(int)b.size())
        swap(a,b);
    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;
        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);

        s[p].clear();
        s[p] = Merge(s[i],s[p]);
    }
    cout<<ans<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 15516 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -