답안 #828207

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
828207 2023-08-17T06:39:39 Z jlallas384 낙하산 고리들 (IOI12_rings) C++17
38 / 100
4000 ms 207628 KB
#include <bits/stdc++.h>
using namespace std;
 
 
 
struct ufds{
    vector<int> sz, par;
    ufds(){}
    ufds(int n): sz(n, 1), par(n){
        iota(par.begin(), par.end(), 0);
    }
    int find(int a){
        return par[a] == a ? a : par[a] = find(par[a]);
    }
    int unite(int a, int b){
        a = find(a), b = find(b);
        if(a == b) return 0;
        if(sz[a] < sz[b]) swap(a, b);
        par[b] = a;
        sz[a] += sz[b];
        return 1;
    }
};
 
set<int> ans;
vector<vector<int>> g, tree;
vector<int> deg;
int n = 0;
ufds ds;
 
int bad = 0;
int d4 = 0;
 
void Init(int N){
    assert(n == 0);
    n = N;
    g.resize(n);
    tree.resize(n);
    deg.resize(n);
    for(int i = 0; i < n; i++){
        ans.insert(i);
    }
    ds = ufds(n);
}
 
void proc(int a, int add = 1){
    if(deg[a] == 4){
        if(add){
            d4++;
            if(d4 == 2) ans = {};
        }
        if(!ans.count(a)) ans = {};
        else ans = {a};
    }else if(deg[a] == 3){
        set<int> nans;
        if(ans.count(a)) nans.insert(a);
        for(int u: g[a]){
            if(ans.count(u)) nans.insert(u);
        }
        ans = nans;
    }
}
 
int CountCritical(){    
    if(bad) return 0;
    else return ans.size();
}
 
 
 
 
int cyc = 0;
 
vector<int> path;
int dfs(int v, int p, int x){
    path.push_back(v);
    if(v == x) return 1;
    for(int u: tree[v]) if(u != p){
        if(dfs(u, v, x)) return 1;
    }
    path.pop_back();
    return 0;
}
 
vector<pair<int,int>> eds;
map<int, ufds> mp;
 
void Link(int a, int b){
    int res = ds.unite(a, b);
    deg[a]++, deg[b]++;
    g[a].push_back(b);
    g[b].push_back(a);
    eds.emplace_back(a, b);
    proc(a), proc(b);
    if(cyc == 2){
        set<int> nans;
        for(int x: ans){
            int bad = 0;
            if(a != x && b != x && !mp[x].unite(a, b)){
                bad = 1;
            }
            if(!bad) nans.insert(x);
        }
        ans = nans;
        assert(ans.size() <= 2);
    }
    if(!res){
        if(!cyc){
            dfs(a, -1, b);
            ans = {};
            for(int x: path){
                ans.insert(x);
            }
            for(int i = 0; i < n; i++){
                proc(i, 0);
            }
            cyc = 1;
        }else{
            if(cyc == 1){
                set<int> nans;
                for(int x: ans){
                    ufds f(n);
                    int tbad = 0;
                    for(auto [u, v]: eds){
                        if(u != x && v != x){
                            if(!f.unite(u, v)) tbad = 1;
                        }
                    }
                    if(!tbad) nans.insert(x), mp[x] = f;;
                }
                ans = nans;
            }
            cyc = 2;
        }
    }else{
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 852 KB Output is correct
3 Correct 3 ms 980 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 852 KB Output is correct
6 Correct 3 ms 1364 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 4 ms 980 KB Output is correct
9 Correct 3 ms 980 KB Output is correct
10 Correct 3 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 558 ms 91952 KB Output is correct
2 Correct 1068 ms 116804 KB Output is correct
3 Correct 1247 ms 120420 KB Output is correct
4 Correct 1374 ms 176264 KB Output is correct
5 Correct 1359 ms 177680 KB Output is correct
6 Correct 1611 ms 207628 KB Output is correct
7 Correct 1195 ms 119224 KB Output is correct
8 Correct 1256 ms 159132 KB Output is correct
9 Correct 1366 ms 174544 KB Output is correct
10 Execution timed out 4083 ms 172384 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 852 KB Output is correct
3 Correct 3 ms 980 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 852 KB Output is correct
6 Correct 3 ms 1364 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 4 ms 980 KB Output is correct
9 Correct 3 ms 980 KB Output is correct
10 Correct 3 ms 1108 KB Output is correct
11 Correct 3 ms 1108 KB Output is correct
12 Correct 5 ms 2004 KB Output is correct
13 Correct 5 ms 1876 KB Output is correct
14 Correct 5 ms 1364 KB Output is correct
15 Correct 7 ms 2388 KB Output is correct
16 Correct 9 ms 2004 KB Output is correct
17 Correct 6 ms 1620 KB Output is correct
18 Correct 7 ms 2592 KB Output is correct
19 Correct 5 ms 2164 KB Output is correct
20 Correct 5 ms 2004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 852 KB Output is correct
3 Correct 3 ms 980 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 852 KB Output is correct
6 Correct 3 ms 1364 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 4 ms 980 KB Output is correct
9 Correct 3 ms 980 KB Output is correct
10 Correct 3 ms 1108 KB Output is correct
11 Correct 3 ms 1108 KB Output is correct
12 Correct 5 ms 2004 KB Output is correct
13 Correct 5 ms 1876 KB Output is correct
14 Correct 5 ms 1364 KB Output is correct
15 Correct 7 ms 2388 KB Output is correct
16 Correct 9 ms 2004 KB Output is correct
17 Correct 6 ms 1620 KB Output is correct
18 Correct 7 ms 2592 KB Output is correct
19 Correct 5 ms 2164 KB Output is correct
20 Correct 5 ms 2004 KB Output is correct
21 Correct 22 ms 7692 KB Output is correct
22 Correct 38 ms 11968 KB Output is correct
23 Correct 47 ms 14992 KB Output is correct
24 Correct 63 ms 10168 KB Output is correct
25 Correct 30 ms 10972 KB Output is correct
26 Incorrect 47 ms 10572 KB Output isn't correct
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 852 KB Output is correct
3 Correct 3 ms 980 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 852 KB Output is correct
6 Correct 3 ms 1364 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 4 ms 980 KB Output is correct
9 Correct 3 ms 980 KB Output is correct
10 Correct 3 ms 1108 KB Output is correct
11 Correct 558 ms 91952 KB Output is correct
12 Correct 1068 ms 116804 KB Output is correct
13 Correct 1247 ms 120420 KB Output is correct
14 Correct 1374 ms 176264 KB Output is correct
15 Correct 1359 ms 177680 KB Output is correct
16 Correct 1611 ms 207628 KB Output is correct
17 Correct 1195 ms 119224 KB Output is correct
18 Correct 1256 ms 159132 KB Output is correct
19 Correct 1366 ms 174544 KB Output is correct
20 Execution timed out 4083 ms 172384 KB Time limit exceeded
21 Halted 0 ms 0 KB -