Submission #434798

# Submission time Handle Problem Language Result Execution time Memory
434798 2021-06-21T20:33:34 Z 2qbingxuan Parachute rings (IOI12_rings) C++14
0 / 100
137 ms 262148 KB
#include <bits/stdc++.h>
#ifdef local
#define debug(x...) qqbx(#x, x)
#define pary(x...) danb(#x, x)
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
template <typename ...T> void qqbx(const char *s, T ...a) {
    int cnt = sizeof...(T);
    ((std::cerr << "(" << s << ") = ("), ..., (std::cerr << a << (--cnt ? ", " : ")\n")));
}
template <typename T> void danb(const char *t, T L, T R) {
    std::cerr << "[ " << t << " ] = [ ";
    for (int f = 0; L != R; ++L) std::cerr << (f++ ? ", " : "") << *L;
    std::cerr << " ]\n";
}
#else
#define debug(...) ((void)0)
#define pary(...) ((void)0)
#define safe ((void)0)
#endif // local

using namespace std;

// #include "lib1270.h"
const int maxn = 1000025, K = 100;
struct Dsu {
    int pa[maxn], rk[maxn];
    int deg[maxn];
    bool ok;
    void init(int n) {
        for (int i = 0; i < n; i++) pa[i] = i, rk[i] = 0, deg[i] = 0;
        ok = true;
    }
    int anc(int x) { return x==pa[x] ? x : pa[x]=anc(pa[x]); }
    bool join(int x, int y) {
        if (++deg[x] == 3) ok = false;
        if (++deg[y] == 3) ok = false;
        if ((x=anc(x)) == (y=anc(y))) return ok = false;
        if (rk[x] < rk[y]) swap(x, y);
        return pa[y] = x, rk[x]!=rk[y] || ++rk[x];
    }
} dsu[K];
vector<int> cand;
pair<int,int> E[maxn];
vector<int> adj[maxn];
bool used[maxn];
int tot, N;
void Init(int _N) {
    N = _N;
    for (int i = 0; i < K; i++)
        dsu[i].init(N);
    for (int i = 0; i < N; i++)
        adj[i].clear();
    for (int i = 0; i < N; i++)
        used[i] = false;
    cand.clear();
    tot = 0;
}
void addCand(int x) {
    if (used[x]) return;
    used[x] = true;
    if (cand.size() > K) return;
    int pos = cand.size();
    cand.push_back(x);
    if (cand.size() > K) return;
    for (int i = 0; i < tot; i++)
        if (x != E[i].first && x != E[i].second)
            dsu[pos].join(E[i].first, E[i].second);
}
void Link(int a, int b) {
    if (adj[a].size() == 2) {
        addCand(a);
        for (int j: adj[a])
            addCand(j);
    }
    if (adj[b].size() == 2) {
        addCand(b);
        for (int j: adj[b])
            addCand(j);
    }
    E[tot++] = { a, b };
    adj[a].push_back(b);
    adj[b].push_back(a);
    for (int i = 0; i < cand.size(); i++)
        if (a != cand[i] && b != cand[i])
            dsu[i].join(a, b);
}
int CountCritical() {
    if (cand.size() > K) return 0;
    if (cand.size() == 0) return N;
    int ans = 0;
    for (int i = 0; i < cand.size(); i++) if (dsu[i].ok) ++ans;
    return ans;
}
#ifdef local
signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
}
#endif // local

Compilation message

rings.cpp: In function 'void Link(int, int)':
rings.cpp:83:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |     for (int i = 0; i < cand.size(); i++)
      |                     ~~^~~~~~~~~~~~~
rings.cpp: In function 'int CountCritical()':
rings.cpp:91:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |     for (int i = 0; i < cand.size(); i++) if (dsu[i].ok) ++ans;
      |                     ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 17 ms 26316 KB Output is correct
2 Correct 24 ms 31280 KB Output is correct
3 Correct 22 ms 32264 KB Output is correct
4 Incorrect 18 ms 27420 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 137 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 26316 KB Output is correct
2 Correct 24 ms 31280 KB Output is correct
3 Correct 22 ms 32264 KB Output is correct
4 Incorrect 18 ms 27420 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 26316 KB Output is correct
2 Correct 24 ms 31280 KB Output is correct
3 Correct 22 ms 32264 KB Output is correct
4 Incorrect 18 ms 27420 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 26316 KB Output is correct
2 Correct 24 ms 31280 KB Output is correct
3 Correct 22 ms 32264 KB Output is correct
4 Incorrect 18 ms 27420 KB Output isn't correct
5 Halted 0 ms 0 KB -