#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);
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 time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
4 ms |
5204 KB |
Output is correct |
4 |
Correct |
3 ms |
5204 KB |
Output is correct |
5 |
Correct |
3 ms |
5204 KB |
Output is correct |
6 |
Correct |
3 ms |
5204 KB |
Output is correct |
7 |
Correct |
3 ms |
5204 KB |
Output is correct |
8 |
Correct |
3 ms |
5204 KB |
Output is correct |
9 |
Correct |
3 ms |
5204 KB |
Output is correct |
10 |
Correct |
3 ms |
5204 KB |
Output is correct |
11 |
Correct |
3 ms |
5224 KB |
Output is correct |
12 |
Correct |
4 ms |
5204 KB |
Output is correct |
13 |
Correct |
3 ms |
5204 KB |
Output is correct |
14 |
Correct |
5 ms |
5204 KB |
Output is correct |
15 |
Correct |
3 ms |
5204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
4 ms |
5204 KB |
Output is correct |
4 |
Correct |
3 ms |
5204 KB |
Output is correct |
5 |
Correct |
3 ms |
5204 KB |
Output is correct |
6 |
Correct |
3 ms |
5204 KB |
Output is correct |
7 |
Correct |
3 ms |
5204 KB |
Output is correct |
8 |
Correct |
3 ms |
5204 KB |
Output is correct |
9 |
Correct |
3 ms |
5204 KB |
Output is correct |
10 |
Correct |
3 ms |
5204 KB |
Output is correct |
11 |
Correct |
3 ms |
5224 KB |
Output is correct |
12 |
Correct |
4 ms |
5204 KB |
Output is correct |
13 |
Correct |
3 ms |
5204 KB |
Output is correct |
14 |
Correct |
5 ms |
5204 KB |
Output is correct |
15 |
Correct |
3 ms |
5204 KB |
Output is correct |
16 |
Correct |
606 ms |
535856 KB |
Output is correct |
17 |
Correct |
565 ms |
557400 KB |
Output is correct |
18 |
Correct |
593 ms |
591776 KB |
Output is correct |
19 |
Correct |
592 ms |
591692 KB |
Output is correct |
20 |
Correct |
618 ms |
591660 KB |
Output is correct |
21 |
Correct |
465 ms |
488680 KB |
Output is correct |
22 |
Correct |
795 ms |
536676 KB |
Output is correct |
23 |
Correct |
572 ms |
558144 KB |
Output is correct |
24 |
Correct |
598 ms |
591688 KB |
Output is correct |
25 |
Correct |
659 ms |
591684 KB |
Output is correct |
26 |
Correct |
667 ms |
591684 KB |
Output is correct |
27 |
Correct |
444 ms |
446404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
887 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
4 ms |
5204 KB |
Output is correct |
4 |
Correct |
3 ms |
5204 KB |
Output is correct |
5 |
Correct |
3 ms |
5204 KB |
Output is correct |
6 |
Correct |
3 ms |
5204 KB |
Output is correct |
7 |
Correct |
3 ms |
5204 KB |
Output is correct |
8 |
Correct |
3 ms |
5204 KB |
Output is correct |
9 |
Correct |
3 ms |
5204 KB |
Output is correct |
10 |
Correct |
3 ms |
5204 KB |
Output is correct |
11 |
Correct |
3 ms |
5224 KB |
Output is correct |
12 |
Correct |
4 ms |
5204 KB |
Output is correct |
13 |
Correct |
3 ms |
5204 KB |
Output is correct |
14 |
Correct |
5 ms |
5204 KB |
Output is correct |
15 |
Correct |
3 ms |
5204 KB |
Output is correct |
16 |
Correct |
606 ms |
535856 KB |
Output is correct |
17 |
Correct |
565 ms |
557400 KB |
Output is correct |
18 |
Correct |
593 ms |
591776 KB |
Output is correct |
19 |
Correct |
592 ms |
591692 KB |
Output is correct |
20 |
Correct |
618 ms |
591660 KB |
Output is correct |
21 |
Correct |
465 ms |
488680 KB |
Output is correct |
22 |
Correct |
795 ms |
536676 KB |
Output is correct |
23 |
Correct |
572 ms |
558144 KB |
Output is correct |
24 |
Correct |
598 ms |
591688 KB |
Output is correct |
25 |
Correct |
659 ms |
591684 KB |
Output is correct |
26 |
Correct |
667 ms |
591684 KB |
Output is correct |
27 |
Correct |
444 ms |
446404 KB |
Output is correct |
28 |
Runtime error |
887 ms |
1048576 KB |
Execution killed with signal 9 |
29 |
Halted |
0 ms |
0 KB |
- |