답안 #1077034

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1077034 2024-08-26T21:29:29 Z ArthuroWich 낙하산 고리들 (IOI12_rings) C++17
38 / 100
4000 ms 132852 KB
#include<bits/stdc++.h>
using namespace std;
vector<int> adj[1000005], vis;
int n, p[1000005], s[1000005];
bool f = 1;
int find(int x) {
    if (p[x] == x) {
        return x;
    }
    p[x] = find(p[x]);
    return p[x];
}
void merge(int a, int b) {
    a = find(a);
    b = find(b);
    if (a == b) {
        return;
    }
    if (s[b] > s[a]) {
        swap(a, b);
    }
    s[a] += s[b];
    p[b] = a;
}
set<int> st;
void Init(int N_) {
    n = N_;
    for (int i = 0; i < n; i++) {
        st.insert(i);
        p[i] = i;
        s[i] = 1;
    }
}
void dfs(int i, int p, int s) {
    if (vis[i]) {
        f = 0;
        return;
    }
    vis[i] = 1;
    for (int j : adj[i]) {
        if (j == p || j == s) {
            continue;
        }
        dfs(j, i, s);
    }
}
int calc(int a) {
    vis.resize(n, 0);
    vector<int> co(n, 0);
    for (int j : adj[a]) {
        co[j]++;
    }
    f = 1;
    for (int i = 0; i < n; i++) {
        if (i != a && adj[i].size()-co[i] > 2) {
            f = 0;
            break;
        }
        if (vis[i] || i == a) {
            continue;
        }
        dfs(i, -1, a);
    }
    vis.clear();
    return f;
}
int le = -1, pre[1000005];
void dfscyc(int i, int p) {
    if (le != -1) {
        return;
    }
    if (vis[i]) {
        set<int> b;
        pre[i] = p;
        int a = i;
        le = 0;
        a = pre[a];
        if (st.count(a)) {
            if (calc(a)) {
                b.insert(a);
            }
        }
        while(a != i) {
            a = pre[a];
            if (st.count(a)) {
                if (calc(a)) {
                    b.insert(a);
                }
            }
        }
        st = b;
        return;
    }
    vis[i] = 1;
    pre[i] = p;
    for (int j : adj[i]) {
        if (j == p) {
            continue;
        }
        dfscyc(j, i);
    }
}
void cycle(int a) {
    vis.resize(n, 0);
    le = -1;
    dfscyc(a, 0);
    vis.clear();
}
bool cyc = 1, cant = 0;
int s4 = -1;
void Link(int A, int B) {
    adj[A].push_back(B);
    adj[B].push_back(A);
    if (cant || st.size() == 0) {
        return;
    }
    if (cyc && find(A) == find(B)) {
        cycle(A);
    }
    if (find(A) != find(B)) {
        merge(A, B);
    }
    if (adj[A].size() >= 4 && s4 == -1) {
        cyc = 0;
        s4 = A;
        if (st.count(A) && calc(A)) {
            st = {A};
        } else {
            st = {};
        }
    }
    if (adj[B].size() >= 4 && s4 == -1) {
        cyc = 0;
        s4 = B;
        if (st.count(B) && calc(B)) {
            st = {B};
        } else {
            st = {};
        }
    }
    if (adj[A].size() >= 4 && s4 != -1 && s4 != A) {
        st.clear();
        cant = 1;
        return;
    }
    if (adj[B].size() >= 4 && s4 != -1 && s4 != B) {
        st.clear();
        cant = 1;
        return;
    }
    if (adj[A].size() == 3) {
        set<int> b;
        if (st.count(A)) {
            if (calc(A)) {
                b.insert(A);
            }
        }
        for (int j : adj[A]) {
            if (st.count(j)) {
                if (calc(j)) {
                    b.insert(j);
                }
            }
        }
        st = b;
    }
    if (adj[B].size() == 3) {
        set<int> b;
        if (st.count(B)) {
            if (calc(B)) {
                b.insert(B);
            }
        }
        for (int j : adj[B]) {
            if (st.count(j)) {
                if (calc(j)) {
                    b.insert(j);
                }
            }
        }
        st = b;
    }
}
int CountCritical() {
    return st.size();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 25180 KB Output is correct
2 Correct 11 ms 25656 KB Output is correct
3 Correct 9 ms 25692 KB Output is correct
4 Correct 11 ms 25180 KB Output is correct
5 Correct 90 ms 25880 KB Output is correct
6 Correct 262 ms 26460 KB Output is correct
7 Correct 10 ms 25432 KB Output is correct
8 Correct 12 ms 25692 KB Output is correct
9 Correct 15 ms 25688 KB Output is correct
10 Correct 13 ms 25688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 303 ms 76864 KB Output is correct
2 Correct 865 ms 99352 KB Output is correct
3 Correct 668 ms 99704 KB Output is correct
4 Execution timed out 4033 ms 132852 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 25180 KB Output is correct
2 Correct 11 ms 25656 KB Output is correct
3 Correct 9 ms 25692 KB Output is correct
4 Correct 11 ms 25180 KB Output is correct
5 Correct 90 ms 25880 KB Output is correct
6 Correct 262 ms 26460 KB Output is correct
7 Correct 10 ms 25432 KB Output is correct
8 Correct 12 ms 25692 KB Output is correct
9 Correct 15 ms 25688 KB Output is correct
10 Correct 13 ms 25688 KB Output is correct
11 Correct 11 ms 25692 KB Output is correct
12 Correct 27 ms 26384 KB Output is correct
13 Correct 15 ms 26048 KB Output is correct
14 Correct 151 ms 25780 KB Output is correct
15 Correct 420 ms 26616 KB Output is correct
16 Correct 20 ms 26364 KB Output is correct
17 Correct 13 ms 25948 KB Output is correct
18 Correct 15 ms 26716 KB Output is correct
19 Correct 76 ms 26444 KB Output is correct
20 Correct 14 ms 26200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 25180 KB Output is correct
2 Correct 11 ms 25656 KB Output is correct
3 Correct 9 ms 25692 KB Output is correct
4 Correct 11 ms 25180 KB Output is correct
5 Correct 90 ms 25880 KB Output is correct
6 Correct 262 ms 26460 KB Output is correct
7 Correct 10 ms 25432 KB Output is correct
8 Correct 12 ms 25692 KB Output is correct
9 Correct 15 ms 25688 KB Output is correct
10 Correct 13 ms 25688 KB Output is correct
11 Correct 11 ms 25692 KB Output is correct
12 Correct 27 ms 26384 KB Output is correct
13 Correct 15 ms 26048 KB Output is correct
14 Correct 151 ms 25780 KB Output is correct
15 Correct 420 ms 26616 KB Output is correct
16 Correct 20 ms 26364 KB Output is correct
17 Correct 13 ms 25948 KB Output is correct
18 Correct 15 ms 26716 KB Output is correct
19 Correct 76 ms 26444 KB Output is correct
20 Correct 14 ms 26200 KB Output is correct
21 Correct 26 ms 29268 KB Output is correct
22 Correct 39 ms 31828 KB Output is correct
23 Correct 46 ms 33364 KB Output is correct
24 Execution timed out 4069 ms 31760 KB Time limit exceeded
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 25180 KB Output is correct
2 Correct 11 ms 25656 KB Output is correct
3 Correct 9 ms 25692 KB Output is correct
4 Correct 11 ms 25180 KB Output is correct
5 Correct 90 ms 25880 KB Output is correct
6 Correct 262 ms 26460 KB Output is correct
7 Correct 10 ms 25432 KB Output is correct
8 Correct 12 ms 25692 KB Output is correct
9 Correct 15 ms 25688 KB Output is correct
10 Correct 13 ms 25688 KB Output is correct
11 Correct 303 ms 76864 KB Output is correct
12 Correct 865 ms 99352 KB Output is correct
13 Correct 668 ms 99704 KB Output is correct
14 Execution timed out 4033 ms 132852 KB Time limit exceeded
15 Halted 0 ms 0 KB -