#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+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(a.size()<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;
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()==0)continue;
s[p] = Merge(s[i],s[p]);
}
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
9684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
9684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
771 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
9684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |