Submission #821354

# Submission time Handle Problem Language Result Execution time Memory
821354 2023-08-11T09:30:04 Z danikoynov Marshmallow Molecules (CCO19_day2problem2) C++14
25 / 25
108 ms 26700 KB
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int maxn = 1e5 + 10;
int n, m;

vector < int > adj[maxn];
set < int > st[maxn];
void solve()
{
    cin >> n >> m;
    for (int i = 1; i <= m; i ++)
    {
        int a, b;
        cin >> a >> b;
        st[a].insert(b);
    }

    ll ans = 0;
    for (int i = 1; i <= n; i ++)
    {
        while(!st[i].empty() && *st[i].begin() <= i)
        {
            st[i].erase(st[i].begin());
        }
        if (st[i].empty())
            continue;

        ///for (int u : st[i])
           /// cout << i << " : " << u << endl;
        ans = ans + (ll)(st[i].size());
        int u = *st[i].begin();

        if (st[u].size() < st[i].size())
            swap(st[u], st[i]);

        for (int v : st[i])
        {
            st[u].insert(v);
        }
    }

    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}
/**
5 3

1 2
1 3
3 4
*/
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7252 KB Output is correct
2 Correct 3 ms 7252 KB Output is correct
3 Correct 6 ms 7508 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7484 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7468 KB Output is correct
9 Correct 3 ms 7252 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Correct 4 ms 7404 KB Output is correct
12 Correct 5 ms 7380 KB Output is correct
13 Correct 6 ms 7380 KB Output is correct
14 Correct 4 ms 7472 KB Output is correct
15 Correct 4 ms 7252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7252 KB Output is correct
2 Correct 3 ms 7252 KB Output is correct
3 Correct 6 ms 7508 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7484 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7468 KB Output is correct
9 Correct 3 ms 7252 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Correct 4 ms 7404 KB Output is correct
12 Correct 5 ms 7380 KB Output is correct
13 Correct 6 ms 7380 KB Output is correct
14 Correct 4 ms 7472 KB Output is correct
15 Correct 4 ms 7252 KB Output is correct
16 Correct 62 ms 12552 KB Output is correct
17 Correct 61 ms 12480 KB Output is correct
18 Correct 60 ms 12000 KB Output is correct
19 Correct 61 ms 12020 KB Output is correct
20 Correct 61 ms 11952 KB Output is correct
21 Correct 6 ms 7636 KB Output is correct
22 Correct 62 ms 12568 KB Output is correct
23 Correct 63 ms 12412 KB Output is correct
24 Correct 68 ms 12016 KB Output is correct
25 Correct 61 ms 11948 KB Output is correct
26 Correct 61 ms 11948 KB Output is correct
27 Correct 13 ms 7672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 15276 KB Output is correct
2 Correct 100 ms 13760 KB Output is correct
3 Correct 72 ms 12852 KB Output is correct
4 Correct 77 ms 15168 KB Output is correct
5 Correct 87 ms 13696 KB Output is correct
6 Correct 70 ms 12832 KB Output is correct
7 Correct 90 ms 15276 KB Output is correct
8 Correct 78 ms 13736 KB Output is correct
9 Correct 101 ms 12828 KB Output is correct
10 Correct 81 ms 15168 KB Output is correct
11 Correct 76 ms 13688 KB Output is correct
12 Correct 78 ms 12816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7252 KB Output is correct
2 Correct 3 ms 7252 KB Output is correct
3 Correct 6 ms 7508 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7484 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7468 KB Output is correct
9 Correct 3 ms 7252 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Correct 4 ms 7404 KB Output is correct
12 Correct 5 ms 7380 KB Output is correct
13 Correct 6 ms 7380 KB Output is correct
14 Correct 4 ms 7472 KB Output is correct
15 Correct 4 ms 7252 KB Output is correct
16 Correct 62 ms 12552 KB Output is correct
17 Correct 61 ms 12480 KB Output is correct
18 Correct 60 ms 12000 KB Output is correct
19 Correct 61 ms 12020 KB Output is correct
20 Correct 61 ms 11952 KB Output is correct
21 Correct 6 ms 7636 KB Output is correct
22 Correct 62 ms 12568 KB Output is correct
23 Correct 63 ms 12412 KB Output is correct
24 Correct 68 ms 12016 KB Output is correct
25 Correct 61 ms 11948 KB Output is correct
26 Correct 61 ms 11948 KB Output is correct
27 Correct 13 ms 7672 KB Output is correct
28 Correct 87 ms 15276 KB Output is correct
29 Correct 100 ms 13760 KB Output is correct
30 Correct 72 ms 12852 KB Output is correct
31 Correct 77 ms 15168 KB Output is correct
32 Correct 87 ms 13696 KB Output is correct
33 Correct 70 ms 12832 KB Output is correct
34 Correct 90 ms 15276 KB Output is correct
35 Correct 78 ms 13736 KB Output is correct
36 Correct 101 ms 12828 KB Output is correct
37 Correct 81 ms 15168 KB Output is correct
38 Correct 76 ms 13688 KB Output is correct
39 Correct 78 ms 12816 KB Output is correct
40 Correct 105 ms 23508 KB Output is correct
41 Correct 108 ms 23492 KB Output is correct
42 Correct 99 ms 26668 KB Output is correct
43 Correct 98 ms 26700 KB Output is correct
44 Correct 85 ms 21852 KB Output is correct
45 Correct 102 ms 22016 KB Output is correct
46 Correct 66 ms 12944 KB Output is correct
47 Correct 67 ms 12900 KB Output is correct
48 Correct 65 ms 12612 KB Output is correct
49 Correct 64 ms 12604 KB Output is correct
50 Correct 78 ms 15180 KB Output is correct
51 Correct 78 ms 13780 KB Output is correct
52 Correct 84 ms 12920 KB Output is correct
53 Correct 72 ms 14540 KB Output is correct
54 Correct 85 ms 15788 KB Output is correct
55 Correct 90 ms 17684 KB Output is correct
56 Correct 71 ms 14768 KB Output is correct
57 Correct 59 ms 12020 KB Output is correct