Submission #259353

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

using namespace std;

const int k_N = 1e6 + 3;

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

    int cycles_all, mx_all;
    int cycle_node;

    DSU(){
       
    }

    void update_d(int u){
        d[u]++;
        mx[get_p(u)] = max(mx[get_p(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;
            cycles[i] = 0;
            mx[i] = 0;
            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]];
        cycles[p[u]] += cycles[p[v]];
        mx[p[u]] = max(mx[p[u]], mx[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++;
            cycles[get_p(a)]++;
        }
    }
};

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){
        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);

    bool curr = false;
    if(dsu.mx_all < 3 && adj[a].size() == 3){
        do_cand(a);
        curr = true;
    }
    else if(dsu.mx_all < 3 && adj[b].size() == 3){
        do_cand(b);
        curr = true;
    }

    dsu.add(a, b);

    if(dsu.mx_all >= 3 && !curr){
        for(int i = 0; i < 4; ++i){
            if(a == cand[i] || b == cand[i]) continue;
            dsu_cand[i].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:87: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 23936 KB Output is correct
2 Incorrect 17 ms 24448 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 541 ms 55356 KB Output is correct
2 Incorrect 1588 ms 96708 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23936 KB Output is correct
2 Incorrect 17 ms 24448 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23936 KB Output is correct
2 Incorrect 17 ms 24448 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23936 KB Output is correct
2 Incorrect 17 ms 24448 KB Output isn't correct
3 Halted 0 ms 0 KB -