답안 #1013449

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1013449 2024-07-03T14:40:16 Z Ludissey 낙하산 고리들 (IOI12_rings) C++14
55 / 100
4000 ms 149724 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
int n;
bool hasloop=false;
vector<vector<int>> neigh;
vector<int> visited;
vector<int> parent;
vector<int> pr;
vector<int> sz;
vector<int> crit;
vector<int> incycle;
vector<int> iscycle;
vector<int> orig;
int timer=0;
int exceptation=-1;
bool cycl=0;
int cc=0;
int c=0;
int upds=0;

int getParent(int a) { 
    if(parent[a]==a) return a;
    else return parent[a]=getParent(parent[a]); 
}

void unite(int a, int b){
    a=getParent(a); b=getParent(b);
    if(a==b) return;
    if(sz[b]>sz[a]) swap(a,b);
    sz[a]+=sz[b];
    parent[a]=b;
}

void detect_cycle(int x, int p) {
    if(visited[x]==2) return;
    if (visited[x] == 1) {
        vector<int> v;
        iscycle[x]=true;
        incycle.push_back(x);
        int cr=pr[x];
        while (cr!=x) {
            incycle.push_back(cr);
            iscycle[cr]=true;
            cr=pr[cr];
        } 
        return;
    }
    pr[x]=p;
    visited[x]=1;
    for (int to : neigh[x]) {
        if (to==p) continue;
        detect_cycle(to,x);
    }
    visited[x]=2;
}


void get_origin(int x, int p,int og) {
    if(orig[x]>=0) return;
    orig[x]=og;
    for (int to : neigh[x]) {
        if (to==p||iscycle[to]) continue;
        get_origin(to,x,orig[x]);
    }
}

void Init(signed N_) {
    n = N_;
    parent.resize(n);
    visited.resize(n,0);
    neigh.resize(n);
    orig.resize(n,-1);
    cc=0;
    sz.resize(n,1);
    iscycle.resize(n,0);
    pr.resize(n,-1);
    crit.resize(n,0);
    upds=0;
    for (int i = 0; i < n; i++) parent[i]=i;
}

void update_crit(int X){
    if(sz(neigh[X])==3){
        crit[neigh[X][0]]++;
        crit[neigh[X][1]]++;
        crit[neigh[X][2]]++;
        crit[X]++;
        upds++;
    }else if(sz(neigh[X])>3){
        crit[X]++;
        upds++;
    }
}

void case1(int A, int B){ //two vertex of different sets O(1);
    unite(A,B);
    if(orig[A]>=0&&orig[B]<0) get_origin(B,A,orig[A]);
    else if(orig[B]>=0&&orig[A]<0) get_origin(A,B,orig[B]);
    update_crit(A);
    update_crit(B);
}
void case2(int A, int B){ //two vertex of same sets !! NO CYCLE !! O(N+M)
    detect_cycle(A,B);
    cycl=1;
    for (int i = 0; i < sz(incycle); i++) crit[incycle[i]]++;
    upds++;
    visited.clear();
    visited.resize(n,0);
    for (int i = 0; i < sz(incycle); i++) get_origin(incycle[i],-1,incycle[i]);
    case1(A,B);
}
void case3(int A, int B){ //two vertex of same sets !! CYCLE !! O(1)
    //cerr << "case 3";
    if(orig[A]<0||orig[B]<0) { upds++; return; }
    crit[orig[A]]++;
    if(orig[A]!=orig[B]) crit[orig[B]]++;
    upds++;
    update_crit(A);
    update_crit(B);
    update_crit(orig[A]);
    update_crit(orig[B]);
}
void Link(signed A, signed B) {
    neigh[A].push_back(B);
    neigh[B].push_back(A);
    if(getParent(A)==getParent(B)){
        if(cycl) case3(A,B);
        else case2(A,B);
    }else{
        case1(A,B);
    }
}

signed CountCritical() {
    c=0;
    for (int i = 0; i < n; i++) if(crit[i]==upds) c++;
    return c;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 2 ms 1116 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 217 ms 61216 KB Output is correct
2 Correct 511 ms 93868 KB Output is correct
3 Correct 770 ms 118364 KB Output is correct
4 Correct 674 ms 116820 KB Output is correct
5 Correct 667 ms 118352 KB Output is correct
6 Correct 861 ms 149724 KB Output is correct
7 Correct 753 ms 117076 KB Output is correct
8 Correct 653 ms 109388 KB Output is correct
9 Correct 658 ms 116820 KB Output is correct
10 Correct 488 ms 115280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 2 ms 1116 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 3 ms 860 KB Output is correct
12 Correct 4 ms 1880 KB Output is correct
13 Correct 4 ms 1884 KB Output is correct
14 Correct 3 ms 1372 KB Output is correct
15 Correct 4 ms 2356 KB Output is correct
16 Correct 4 ms 1628 KB Output is correct
17 Correct 4 ms 1628 KB Output is correct
18 Correct 5 ms 2396 KB Output is correct
19 Correct 3 ms 1628 KB Output is correct
20 Correct 4 ms 1556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 2 ms 1116 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 3 ms 860 KB Output is correct
12 Correct 4 ms 1880 KB Output is correct
13 Correct 4 ms 1884 KB Output is correct
14 Correct 3 ms 1372 KB Output is correct
15 Correct 4 ms 2356 KB Output is correct
16 Correct 4 ms 1628 KB Output is correct
17 Correct 4 ms 1628 KB Output is correct
18 Correct 5 ms 2396 KB Output is correct
19 Correct 3 ms 1628 KB Output is correct
20 Correct 4 ms 1556 KB Output is correct
21 Correct 426 ms 5664 KB Output is correct
22 Correct 1107 ms 8788 KB Output is correct
23 Correct 1742 ms 10880 KB Output is correct
24 Correct 2889 ms 10204 KB Output is correct
25 Correct 2731 ms 8696 KB Output is correct
26 Correct 2210 ms 10732 KB Output is correct
27 Correct 642 ms 10836 KB Output is correct
28 Correct 360 ms 11092 KB Output is correct
29 Execution timed out 4070 ms 10284 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 2 ms 1116 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 217 ms 61216 KB Output is correct
12 Correct 511 ms 93868 KB Output is correct
13 Correct 770 ms 118364 KB Output is correct
14 Correct 674 ms 116820 KB Output is correct
15 Correct 667 ms 118352 KB Output is correct
16 Correct 861 ms 149724 KB Output is correct
17 Correct 753 ms 117076 KB Output is correct
18 Correct 653 ms 109388 KB Output is correct
19 Correct 658 ms 116820 KB Output is correct
20 Correct 488 ms 115280 KB Output is correct
21 Correct 3 ms 860 KB Output is correct
22 Correct 4 ms 1880 KB Output is correct
23 Correct 4 ms 1884 KB Output is correct
24 Correct 3 ms 1372 KB Output is correct
25 Correct 4 ms 2356 KB Output is correct
26 Correct 4 ms 1628 KB Output is correct
27 Correct 4 ms 1628 KB Output is correct
28 Correct 5 ms 2396 KB Output is correct
29 Correct 3 ms 1628 KB Output is correct
30 Correct 4 ms 1556 KB Output is correct
31 Correct 426 ms 5664 KB Output is correct
32 Correct 1107 ms 8788 KB Output is correct
33 Correct 1742 ms 10880 KB Output is correct
34 Correct 2889 ms 10204 KB Output is correct
35 Correct 2731 ms 8696 KB Output is correct
36 Correct 2210 ms 10732 KB Output is correct
37 Correct 642 ms 10836 KB Output is correct
38 Correct 360 ms 11092 KB Output is correct
39 Execution timed out 4070 ms 10284 KB Time limit exceeded
40 Halted 0 ms 0 KB -