Submission #259370

# Submission time Handle Problem Language Result Execution time Memory
259370 2020-08-07T16:54:57 Z Sorting Parachute rings (IOI12_rings) C++17
0 / 100
2025 ms 118996 KB
#include <bits/stdc++.h>

using namespace std;

const int k_N = 1e6 + 3;

struct DSU{
    int p[k_N], sz[k_N];
    int d[k_N];

    int cycles_all, mx_all;
    int cycle_node;

    DSU(){
       
    }

    void update_d(int u){
        d[u]++;
    }

    void resize(int n){
        cycles_all = 0;
        mx_all = 0;
        cycle_node = -1;

        for(int i = 0; i < n; ++i){
            p[i] = i;
            sz[i] = 1;
            d[i] = 0;
        }
    }

    int get_p(int u){
        if(p[u] == u) return u;
        return p[u] = get_p(p[u]);
    }

    bool unite(int u, int v){
        if(get_p(u) == get_p(v))
            return false;

        if(sz[p[u]] < sz[p[v]])
            swap(u, v);

        sz[p[u]] += sz[p[v]];
        p[p[v]] = p[u];

        return true;
    }

    void add(int a, int b){
        update_d(a);
        update_d(b);

        mx_all = max(mx_all, max(d[a], d[b]));

        if(!unite(a, b)){
            cycle_node = a;
            cycles_all++;
        }
    }
};

int n;
vector<pair<int, int>> edges;
vector<int> adj[k_N];

DSU dsu, dsu_cand[4];
int cand[4];

void Init(int n_){
    n = n_;

    dsu.resize(n);
}

void do_cand(int a){
    cand[0] = a;
    for(int i = 0; i < adj[a].size(); ++i)
        cand[i + 1] = adj[a][i];
    
    for(int i = 0; i < 4; ++i){
        dsu_cand[i].resize(n);
        for(auto [u, v]: edges){
            if(u == a || v == a) continue;
            dsu_cand[i].add(u, v);
        }
    }
}

void Link(int a, int b){
    edges.push_back({a, b});
    adj[a].push_back(b);
    adj[b].push_back(a);

    if(dsu.mx_all < 3 && adj[a].size() == 3)
        do_cand(a);
    else if(dsu.mx_all < 3 && adj[b].size() == 3)
        do_cand(b);

    if(dsu.mx_all >= 3){
        for(int i = 0; i < 4; ++i){
            if(a == cand[i] || b == cand[i]) continue;
            dsu_cand[i].add(a, b);
        }
    }

    dsu.add(a, b);
}

int CountCritical(){
    if(dsu.mx_all <= 2){
        if(dsu.cycles_all >= 2)
            return 0;
        if(dsu.cycles_all == 1)
            return dsu.sz[dsu.get_p(dsu.cycle_node)];
        return n;
    }

    int ans = 0;
    for(int i = 0; i < 4; ++i){
        if(dsu_cand[i].mx_all < 3 && dsu_cand[i].cycles_all == 0)
            ans++;
    }

    return ans;
}

Compilation message

rings.cpp: In function 'void do_cand(int)':
rings.cpp:80:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < adj[a].size(); ++i)
                    ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23808 KB Output is correct
2 Incorrect 19 ms 24576 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 481 ms 53212 KB Output is correct
2 Correct 1668 ms 103888 KB Output is correct
3 Correct 2025 ms 118996 KB Output is correct
4 Correct 1260 ms 76460 KB Output is correct
5 Correct 1245 ms 76468 KB Output is correct
6 Correct 1251 ms 75088 KB Output is correct
7 Correct 1760 ms 117876 KB Output is correct
8 Incorrect 1744 ms 116944 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23808 KB Output is correct
2 Incorrect 19 ms 24576 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23808 KB Output is correct
2 Incorrect 19 ms 24576 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23808 KB Output is correct
2 Incorrect 19 ms 24576 KB Output isn't correct
3 Halted 0 ms 0 KB -