Submission #1046531

# Submission time Handle Problem Language Result Execution time Memory
1046531 2024-08-06T16:15:53 Z Andrey Marshmallow Molecules (CCO19_day2problem2) C++14
0 / 25
24 ms 19004 KB
#include<bits/stdc++.h>
using namespace std;

vector<int> dsu(100001);
vector<int> haha[100001];
vector<int> bruh[100001];
set<int> idk[100001];

int calc(int a) {
    int c = a;
    while(dsu[c] != c) {
        c = dsu[c];
    }
    int e = a;
    while(dsu[e] != e) {
        int d = dsu[e];
        dsu[e] = c;
        e = d;
    }
    return c;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m,a,b;
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        dsu[i] = i;
    }
    long long ans = 0;
    for(int i = 0; i < m; i++) {
        cin >> a >> b;
        haha[a].push_back(b);
        bruh[b].push_back(a);
    }
    for(int i = 1; i <= n; i++) {
        vector<int> wut(0);
        int big = -1,p = -1;
        for(int v: bruh[i]) {
            int x = calc(v);
            wut.push_back(x);
            if(idk[x].size() > big) {
                big = idk[x].size();
                p = x;
            }
        }
        if(p != -1) {
            swap(idk[i],idk[p]);
            sort(wut.begin(),wut.end());
            for(int j = 0; j < wut.size(); j++) {
                if((j == 0 || wut[j] != wut[j-1]) && wut[j] != p) {
                    int c = wut[j];
                    dsu[c] = i;
                    while(!idk[c].empty()) {
                        int x = *idk[c].lower_bound(-INT_MAX);
                        idk[i].insert(x);
                        idk[c].erase(x);
                    }
                }
            }
        }
        for(int v: haha[i]) {
            idk[i].insert(v);
        }
        idk[i].erase(i);
        ans+=idk[i].size();
    }
    cout << ans;
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:45:30: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   45 |             if(idk[x].size() > big) {
      |                ~~~~~~~~~~~~~~^~~~~
Main.cpp:53:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |             for(int j = 0; j < wut.size(); j++) {
      |                            ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 10076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 10076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 19004 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 10076 KB Output isn't correct
2 Halted 0 ms 0 KB -