Submission #736574

# Submission time Handle Problem Language Result Execution time Memory
736574 2023-05-06T00:55:13 Z horiseun Parachute rings (IOI12_rings) C++17
52 / 100
4000 ms 71944 KB
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;

#define f first
#define s second

int n, cycsz;
bool nne;
vector<int> adj[1000005];
vector<pair<int, int>> edges;

struct UnionFind1 {
    int rt, par[1000005], deg[1000005];
    bool vld;

    int find(int x) {
        return par[x] == x ? x : par[x] = find(par[x]);
    }

    void merge(int x, int y) {
        if (!vld || x == rt || y == rt) return;
        int px = find(x), py = find(y);
        if (deg[x] == 2 || deg[y] == 2 || px == py) {
            vld = false;
            return;
        }
        deg[x]++;
        deg[y]++;
        par[px] = py;
    }
    
    UnionFind1(int root) {
        rt = root;
        vld = true;
        for (int i = 0; i < n; i++) {
            par[i] = i;
            deg[i] = 0;
        }
        for (pair<int, int> edge : edges) {
            merge(edge.f, edge.s);
        }
    }
};

int par[1000005], sz[1000005];
vector<UnionFind1> uf;

static int find(int x) {
    return par[x] == x ? x : par[x] = find(par[x]);
}

static bool merge(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    sz[x] += sz[y];
    par[y] = x;
    return true;
}

void Init(int N) {
    n = N;
    for (int i = 0; i < n; i++) {
        par[i] = i;
        sz[i] = 1;
    }
}

int CountCritical() {
    if (nne) return 0;
    if (!uf.empty()) {
        int ans = 0;
        for (int i = 0; i < uf.size(); i++) {
            ans += uf[i].vld;
        }
        return ans;
    } else if (cycsz) return cycsz;
    return n;
}

void Link(int a, int b) {
    if (nne) return;
    if (!uf.empty()) {
        for (int i = 0; i < uf.size(); i++) {
            uf[i].merge(a, b);
        }
        return;
    }
    edges.push_back({a, b});
    adj[a].push_back(b);
    adj[b].push_back(a);
    if (adj[a].size() < adj[b].size()) swap(a, b);
    if (adj[a].size() == 3) {
        uf.push_back(UnionFind1(a));
        for (int i : adj[a]) {
            uf.push_back(UnionFind1(i));
        }
        return;
    }
    if (!merge(a, b)) {
        if (cycsz) {
            nne = true;
            return;
        }
        cycsz = sz[find(a)];
    }
}

Compilation message

rings.cpp: In function 'int CountCritical()':
rings.cpp:76:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<UnionFind1>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |         for (int i = 0; i < uf.size(); i++) {
      |                         ~~^~~~~~~~~~~
rings.cpp: In function 'void Link(int, int)':
rings.cpp:87:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<UnionFind1>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |         for (int i = 0; i < uf.size(); i++) {
      |                         ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 19 ms 31572 KB Output is correct
2 Correct 184 ms 70964 KB Output is correct
3 Correct 222 ms 70944 KB Output is correct
4 Correct 47 ms 31660 KB Output is correct
5 Correct 131 ms 31800 KB Output is correct
6 Correct 208 ms 31964 KB Output is correct
7 Correct 55 ms 70852 KB Output is correct
8 Correct 159 ms 31828 KB Output is correct
9 Correct 234 ms 70980 KB Output is correct
10 Correct 224 ms 70980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4042 ms 41820 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 31572 KB Output is correct
2 Correct 184 ms 70964 KB Output is correct
3 Correct 222 ms 70944 KB Output is correct
4 Correct 47 ms 31660 KB Output is correct
5 Correct 131 ms 31800 KB Output is correct
6 Correct 208 ms 31964 KB Output is correct
7 Correct 55 ms 70852 KB Output is correct
8 Correct 159 ms 31828 KB Output is correct
9 Correct 234 ms 70980 KB Output is correct
10 Correct 224 ms 70980 KB Output is correct
11 Correct 223 ms 70992 KB Output is correct
12 Correct 388 ms 71336 KB Output is correct
13 Correct 328 ms 71212 KB Output is correct
14 Correct 286 ms 70868 KB Output is correct
15 Correct 228 ms 70988 KB Output is correct
16 Correct 370 ms 32420 KB Output is correct
17 Correct 401 ms 70932 KB Output is correct
18 Correct 413 ms 71104 KB Output is correct
19 Correct 331 ms 32372 KB Output is correct
20 Correct 414 ms 71296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 31572 KB Output is correct
2 Correct 184 ms 70964 KB Output is correct
3 Correct 222 ms 70944 KB Output is correct
4 Correct 47 ms 31660 KB Output is correct
5 Correct 131 ms 31800 KB Output is correct
6 Correct 208 ms 31964 KB Output is correct
7 Correct 55 ms 70852 KB Output is correct
8 Correct 159 ms 31828 KB Output is correct
9 Correct 234 ms 70980 KB Output is correct
10 Correct 224 ms 70980 KB Output is correct
11 Correct 223 ms 70992 KB Output is correct
12 Correct 388 ms 71336 KB Output is correct
13 Correct 328 ms 71212 KB Output is correct
14 Correct 286 ms 70868 KB Output is correct
15 Correct 228 ms 70988 KB Output is correct
16 Correct 370 ms 32420 KB Output is correct
17 Correct 401 ms 70932 KB Output is correct
18 Correct 413 ms 71104 KB Output is correct
19 Correct 331 ms 32372 KB Output is correct
20 Correct 414 ms 71296 KB Output is correct
21 Correct 1006 ms 33832 KB Output is correct
22 Correct 1526 ms 34832 KB Output is correct
23 Correct 1836 ms 35704 KB Output is correct
24 Correct 1955 ms 71744 KB Output is correct
25 Correct 316 ms 71768 KB Output is correct
26 Correct 2461 ms 71848 KB Output is correct
27 Correct 3139 ms 36448 KB Output is correct
28 Correct 3135 ms 71944 KB Output is correct
29 Correct 1159 ms 71944 KB Output is correct
30 Correct 3531 ms 37480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 31572 KB Output is correct
2 Correct 184 ms 70964 KB Output is correct
3 Correct 222 ms 70944 KB Output is correct
4 Correct 47 ms 31660 KB Output is correct
5 Correct 131 ms 31800 KB Output is correct
6 Correct 208 ms 31964 KB Output is correct
7 Correct 55 ms 70852 KB Output is correct
8 Correct 159 ms 31828 KB Output is correct
9 Correct 234 ms 70980 KB Output is correct
10 Correct 224 ms 70980 KB Output is correct
11 Execution timed out 4042 ms 41820 KB Time limit exceeded
12 Halted 0 ms 0 KB -