답안 #745450

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
745450 2023-05-20T07:02:34 Z Alexandruabcde Marshmallow Molecules (CCO19_day2problem2) C++14
25 / 25
140 ms 24576 KB
#include <bits/stdc++.h>

using namespace std;

typedef pair <int, int> PII;
constexpr int NMAX = 1e5 + 5;

int N, M;
set <int> G[NMAX];

map <PII, int> mp;

void Unite (int x, int y) {
    if (G[x].size() > G[y].size()) swap(G[x], G[y]);

    for (auto it : G[x])
        G[y].insert(it);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N >> M;

    for (int i = 1; i <= M; ++ i ) {
        int x, y;
        cin >> x >> y;

        if (x > y) swap(x, y);
        G[x].insert(y);
    }

    long long answer = 0;
    for (int i = 1; i <= N; ++ i ) {
        answer += 1LL * G[i].size();

        if (G[i].empty()) continue;

        auto it = G[i].begin();
        G[i].erase(it);

        Unite(i, *it);
    }

    cout << answer << '\n';

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5016 KB Output is correct
3 Correct 7 ms 5204 KB Output is correct
4 Correct 5 ms 5068 KB Output is correct
5 Correct 5 ms 5076 KB Output is correct
6 Correct 4 ms 5084 KB Output is correct
7 Correct 4 ms 5076 KB Output is correct
8 Correct 5 ms 5076 KB Output is correct
9 Correct 3 ms 5016 KB Output is correct
10 Correct 4 ms 5080 KB Output is correct
11 Correct 4 ms 5080 KB Output is correct
12 Correct 4 ms 5076 KB Output is correct
13 Correct 4 ms 5076 KB Output is correct
14 Correct 4 ms 5076 KB Output is correct
15 Correct 3 ms 4952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5016 KB Output is correct
3 Correct 7 ms 5204 KB Output is correct
4 Correct 5 ms 5068 KB Output is correct
5 Correct 5 ms 5076 KB Output is correct
6 Correct 4 ms 5084 KB Output is correct
7 Correct 4 ms 5076 KB Output is correct
8 Correct 5 ms 5076 KB Output is correct
9 Correct 3 ms 5016 KB Output is correct
10 Correct 4 ms 5080 KB Output is correct
11 Correct 4 ms 5080 KB Output is correct
12 Correct 4 ms 5076 KB Output is correct
13 Correct 4 ms 5076 KB Output is correct
14 Correct 4 ms 5076 KB Output is correct
15 Correct 3 ms 4952 KB Output is correct
16 Correct 50 ms 10452 KB Output is correct
17 Correct 58 ms 10760 KB Output is correct
18 Correct 66 ms 9700 KB Output is correct
19 Correct 62 ms 10612 KB Output is correct
20 Correct 51 ms 10592 KB Output is correct
21 Correct 5 ms 5460 KB Output is correct
22 Correct 63 ms 11176 KB Output is correct
23 Correct 57 ms 11024 KB Output is correct
24 Correct 59 ms 10532 KB Output is correct
25 Correct 55 ms 10504 KB Output is correct
26 Correct 57 ms 10528 KB Output is correct
27 Correct 7 ms 5332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 100 ms 12940 KB Output is correct
2 Correct 97 ms 12472 KB Output is correct
3 Correct 61 ms 11744 KB Output is correct
4 Correct 74 ms 13992 KB Output is correct
5 Correct 86 ms 12488 KB Output is correct
6 Correct 80 ms 11720 KB Output is correct
7 Correct 76 ms 13928 KB Output is correct
8 Correct 71 ms 12500 KB Output is correct
9 Correct 61 ms 11652 KB Output is correct
10 Correct 75 ms 13876 KB Output is correct
11 Correct 66 ms 12548 KB Output is correct
12 Correct 66 ms 11728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5016 KB Output is correct
3 Correct 7 ms 5204 KB Output is correct
4 Correct 5 ms 5068 KB Output is correct
5 Correct 5 ms 5076 KB Output is correct
6 Correct 4 ms 5084 KB Output is correct
7 Correct 4 ms 5076 KB Output is correct
8 Correct 5 ms 5076 KB Output is correct
9 Correct 3 ms 5016 KB Output is correct
10 Correct 4 ms 5080 KB Output is correct
11 Correct 4 ms 5080 KB Output is correct
12 Correct 4 ms 5076 KB Output is correct
13 Correct 4 ms 5076 KB Output is correct
14 Correct 4 ms 5076 KB Output is correct
15 Correct 3 ms 4952 KB Output is correct
16 Correct 50 ms 10452 KB Output is correct
17 Correct 58 ms 10760 KB Output is correct
18 Correct 66 ms 9700 KB Output is correct
19 Correct 62 ms 10612 KB Output is correct
20 Correct 51 ms 10592 KB Output is correct
21 Correct 5 ms 5460 KB Output is correct
22 Correct 63 ms 11176 KB Output is correct
23 Correct 57 ms 11024 KB Output is correct
24 Correct 59 ms 10532 KB Output is correct
25 Correct 55 ms 10504 KB Output is correct
26 Correct 57 ms 10528 KB Output is correct
27 Correct 7 ms 5332 KB Output is correct
28 Correct 100 ms 12940 KB Output is correct
29 Correct 97 ms 12472 KB Output is correct
30 Correct 61 ms 11744 KB Output is correct
31 Correct 74 ms 13992 KB Output is correct
32 Correct 86 ms 12488 KB Output is correct
33 Correct 80 ms 11720 KB Output is correct
34 Correct 76 ms 13928 KB Output is correct
35 Correct 71 ms 12500 KB Output is correct
36 Correct 61 ms 11652 KB Output is correct
37 Correct 75 ms 13876 KB Output is correct
38 Correct 66 ms 12548 KB Output is correct
39 Correct 66 ms 11728 KB Output is correct
40 Correct 89 ms 21960 KB Output is correct
41 Correct 90 ms 21936 KB Output is correct
42 Correct 140 ms 24576 KB Output is correct
43 Correct 98 ms 24456 KB Output is correct
44 Correct 70 ms 18536 KB Output is correct
45 Correct 83 ms 18540 KB Output is correct
46 Correct 68 ms 10792 KB Output is correct
47 Correct 65 ms 10796 KB Output is correct
48 Correct 60 ms 10760 KB Output is correct
49 Correct 52 ms 10780 KB Output is correct
50 Correct 74 ms 14004 KB Output is correct
51 Correct 66 ms 12432 KB Output is correct
52 Correct 65 ms 11692 KB Output is correct
53 Correct 60 ms 11836 KB Output is correct
54 Correct 104 ms 14096 KB Output is correct
55 Correct 96 ms 16184 KB Output is correct
56 Correct 69 ms 13256 KB Output is correct
57 Correct 46 ms 10484 KB Output is correct