답안 #821452

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
821452 2023-08-11T10:26:26 Z Denkata Marshmallow Molecules (CCO19_day2problem2) C++14
25 / 25
87 ms 24480 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];
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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5016 KB Output is correct
2 Correct 2 ms 5016 KB Output is correct
3 Correct 4 ms 5220 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 3 ms 5076 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 4 ms 5076 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
14 Correct 4 ms 5168 KB Output is correct
15 Correct 2 ms 4980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5016 KB Output is correct
2 Correct 2 ms 5016 KB Output is correct
3 Correct 4 ms 5220 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 3 ms 5076 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 4 ms 5076 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
14 Correct 4 ms 5168 KB Output is correct
15 Correct 2 ms 4980 KB Output is correct
16 Correct 46 ms 10956 KB Output is correct
17 Correct 44 ms 10436 KB Output is correct
18 Correct 44 ms 9956 KB Output is correct
19 Correct 40 ms 9948 KB Output is correct
20 Correct 40 ms 9952 KB Output is correct
21 Correct 6 ms 5416 KB Output is correct
22 Correct 50 ms 10444 KB Output is correct
23 Correct 43 ms 10376 KB Output is correct
24 Correct 37 ms 9752 KB Output is correct
25 Correct 36 ms 9804 KB Output is correct
26 Correct 38 ms 9784 KB Output is correct
27 Correct 6 ms 5420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 13708 KB Output is correct
2 Correct 52 ms 12492 KB Output is correct
3 Correct 50 ms 11636 KB Output is correct
4 Correct 55 ms 13984 KB Output is correct
5 Correct 54 ms 12476 KB Output is correct
6 Correct 46 ms 11684 KB Output is correct
7 Correct 54 ms 13936 KB Output is correct
8 Correct 66 ms 12576 KB Output is correct
9 Correct 49 ms 11736 KB Output is correct
10 Correct 56 ms 13980 KB Output is correct
11 Correct 50 ms 12496 KB Output is correct
12 Correct 45 ms 11728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5016 KB Output is correct
2 Correct 2 ms 5016 KB Output is correct
3 Correct 4 ms 5220 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 3 ms 5076 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 4 ms 5076 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
14 Correct 4 ms 5168 KB Output is correct
15 Correct 2 ms 4980 KB Output is correct
16 Correct 46 ms 10956 KB Output is correct
17 Correct 44 ms 10436 KB Output is correct
18 Correct 44 ms 9956 KB Output is correct
19 Correct 40 ms 9948 KB Output is correct
20 Correct 40 ms 9952 KB Output is correct
21 Correct 6 ms 5416 KB Output is correct
22 Correct 50 ms 10444 KB Output is correct
23 Correct 43 ms 10376 KB Output is correct
24 Correct 37 ms 9752 KB Output is correct
25 Correct 36 ms 9804 KB Output is correct
26 Correct 38 ms 9784 KB Output is correct
27 Correct 6 ms 5420 KB Output is correct
28 Correct 67 ms 13708 KB Output is correct
29 Correct 52 ms 12492 KB Output is correct
30 Correct 50 ms 11636 KB Output is correct
31 Correct 55 ms 13984 KB Output is correct
32 Correct 54 ms 12476 KB Output is correct
33 Correct 46 ms 11684 KB Output is correct
34 Correct 54 ms 13936 KB Output is correct
35 Correct 66 ms 12576 KB Output is correct
36 Correct 49 ms 11736 KB Output is correct
37 Correct 56 ms 13980 KB Output is correct
38 Correct 50 ms 12496 KB Output is correct
39 Correct 45 ms 11728 KB Output is correct
40 Correct 82 ms 21836 KB Output is correct
41 Correct 72 ms 21868 KB Output is correct
42 Correct 74 ms 24460 KB Output is correct
43 Correct 87 ms 24480 KB Output is correct
44 Correct 63 ms 18528 KB Output is correct
45 Correct 54 ms 18452 KB Output is correct
46 Correct 48 ms 10784 KB Output is correct
47 Correct 43 ms 10712 KB Output is correct
48 Correct 39 ms 10752 KB Output is correct
49 Correct 43 ms 10772 KB Output is correct
50 Correct 71 ms 13980 KB Output is correct
51 Correct 50 ms 12448 KB Output is correct
52 Correct 57 ms 11632 KB Output is correct
53 Correct 44 ms 11820 KB Output is correct
54 Correct 64 ms 14196 KB Output is correct
55 Correct 65 ms 16212 KB Output is correct
56 Correct 58 ms 13160 KB Output is correct
57 Correct 37 ms 10436 KB Output is correct