답안 #544955

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
544955 2022-04-03T08:23:39 Z tabr 낙하산 고리들 (IOI12_rings) C++17
55 / 100
4000 ms 84056 KB
#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int n;
vector<vector<int>> g;
vector<int> deg;

void Init(int n_) {
    n = n_;
    g = vector<vector<int>>(n);
    deg = vector<int>(n);
}

void Link(int x, int y) {
    g[x].emplace_back(y);
    g[y].emplace_back(x);
    deg[x]++;
    deg[y]++;
}

struct dsu {
    vector<int> p;
    vector<int> sz;
    int n;

    dsu(int _n) : n(_n) {
        p = vector<int>(n);
        iota(p.begin(), p.end(), 0);
        sz = vector<int>(n, 1);
    }

    inline int get(int x) {
        if (p[x] == x) {
            return x;
        } else {
            return p[x] = get(p[x]);
        }
    }

    inline bool unite(int x, int y) {
        x = get(x);
        y = get(y);
        if (x == y) {
            return false;
        }
        p[x] = y;
        sz[y] += sz[x];
        return true;
    }

    inline bool same(int x, int y) {
        return (get(x) == get(y));
    }

    inline int size(int x) {
        return sz[get(x)];
    }

    inline bool root(int x) {
        return (x == get(x));
    }
};

bool check(int v) {
    dsu uf(n);
    vector<int> new_deg(n);
    for (int i = 0; i < n; i++) {
        for (int j : g[i]) {
            if (i == v || j == v || i > j) {
                continue;
            }
            if (!uf.unite(i, j)) {
                return false;
            }
            new_deg[i]++;
            new_deg[j]++;
        }
    }
    if (*max_element(new_deg.begin(), new_deg.end()) > 2) {
        return false;
    }
    return true;
}

int CountCritical() {
    int mx = *max_element(deg.begin(), deg.end());
    int v = (int) (max_element(deg.begin(), deg.end()) - deg.begin());
    int ans = 0;
    if (mx >= 4) {
        ans += check(v);
    } else if (mx == 3) {
        ans += check(v);
        for (int to : g[v]) {
            ans += check(to);
        }
    } else {
        dsu uf(n);
        vector<int> t;
        for (int i = 0; i < n; i++) {
            for (int j : g[i]) {
                if (i > j) {
                    continue;
                }
                if (!uf.unite(i, j)) {
                    t.emplace_back(uf.get(i));
                }
            }
        }
        if (t.size() == 0) {
            ans = n;
        } else if (t.size() == 1) {
            ans = uf.size(t[0]);
        }
    }
    return ans;
}

#ifdef tabr
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    Init(7);
    cout << CountCritical() << endl;  // 7
    Link(1, 2);
    cout << CountCritical() << endl;  // 7
    Link(0, 5);
    cout << CountCritical() << endl;  // 7
    Link(2, 0);
    cout << CountCritical() << endl;  // 7
    Link(3, 2);
    cout << CountCritical() << endl;  // 4
    Link(3, 5);
    cout << CountCritical() << endl;  // 3
    Link(4, 3);
    cout << CountCritical() << endl;  // 2
    return 0;
}
#endif
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 3 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 393 ms 34952 KB Output is correct
2 Correct 733 ms 67432 KB Output is correct
3 Correct 819 ms 79484 KB Output is correct
4 Correct 971 ms 80204 KB Output is correct
5 Correct 972 ms 80300 KB Output is correct
6 Correct 948 ms 78668 KB Output is correct
7 Correct 785 ms 78376 KB Output is correct
8 Correct 1324 ms 78916 KB Output is correct
9 Correct 1507 ms 84056 KB Output is correct
10 Correct 686 ms 77780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 3 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 14 ms 596 KB Output is correct
12 Correct 34 ms 1052 KB Output is correct
13 Correct 48 ms 1100 KB Output is correct
14 Correct 18 ms 876 KB Output is correct
15 Correct 28 ms 1336 KB Output is correct
16 Correct 24 ms 1064 KB Output is correct
17 Correct 44 ms 1100 KB Output is correct
18 Correct 48 ms 1636 KB Output is correct
19 Correct 26 ms 1108 KB Output is correct
20 Correct 54 ms 1136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 3 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 14 ms 596 KB Output is correct
12 Correct 34 ms 1052 KB Output is correct
13 Correct 48 ms 1100 KB Output is correct
14 Correct 18 ms 876 KB Output is correct
15 Correct 28 ms 1336 KB Output is correct
16 Correct 24 ms 1064 KB Output is correct
17 Correct 44 ms 1100 KB Output is correct
18 Correct 48 ms 1636 KB Output is correct
19 Correct 26 ms 1108 KB Output is correct
20 Correct 54 ms 1136 KB Output is correct
21 Execution timed out 4073 ms 3160 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 3 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 393 ms 34952 KB Output is correct
12 Correct 733 ms 67432 KB Output is correct
13 Correct 819 ms 79484 KB Output is correct
14 Correct 971 ms 80204 KB Output is correct
15 Correct 972 ms 80300 KB Output is correct
16 Correct 948 ms 78668 KB Output is correct
17 Correct 785 ms 78376 KB Output is correct
18 Correct 1324 ms 78916 KB Output is correct
19 Correct 1507 ms 84056 KB Output is correct
20 Correct 686 ms 77780 KB Output is correct
21 Correct 14 ms 596 KB Output is correct
22 Correct 34 ms 1052 KB Output is correct
23 Correct 48 ms 1100 KB Output is correct
24 Correct 18 ms 876 KB Output is correct
25 Correct 28 ms 1336 KB Output is correct
26 Correct 24 ms 1064 KB Output is correct
27 Correct 44 ms 1100 KB Output is correct
28 Correct 48 ms 1636 KB Output is correct
29 Correct 26 ms 1108 KB Output is correct
30 Correct 54 ms 1136 KB Output is correct
31 Execution timed out 4073 ms 3160 KB Time limit exceeded
32 Halted 0 ms 0 KB -