답안 #246556

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
246556 2020-07-09T15:05:20 Z alexandra_udristoiu 낙하산 고리들 (IOI12_rings) C++14
37 / 100
1162 ms 105612 KB
#include<vector>
using namespace std;
const int dim = 1000005;
int n, nr3, nr4, m, num, nrcomp, nrcic;
int r[dim], g[dim], viz[dim], t[dim], frst[dim];
vector<int> v[dim], g3, g4;
int rad(int x){
    while(r[x] > 0){
        x = r[x];
    }
    return x;
}
void upd(int nod){
    if(g[nod] == 4){
        nr3--;
        nr4++;
        g4.push_back(nod);
    }
    else if(g[nod] == 3){
        nr3++;
        g3.push_back(nod);
        for(int i = 0; i < v[nod].size(); i++){
            frst[ v[nod][i] ] = nod;
        }
    }
}
int verif(int nod){
    if(nrcic > 1){
        return 0;
    }
    if(nrcic == 1 && viz[nod] == 0){
        return 0;
    }
    int i, n3 = 0;
    if(g[nod] == 3){
        n3++;
    }
    for(int i = 0; i < v[nod].size(); i++){
        if(g[ v[nod][i] ] == 3){
            n3++;
        }
    }
    if(n3 != nr3){
        return 0;
    }
    return 1;
}

void Init(int N) {
    n = N;
    nrcomp = n;
    for(int i = 0; i < n; i++){
        r[i] = -1;
    }
}

static void dfs(int nod, int tt){
    t[nod] = tt;
    for(int i = 0; i < v[nod].size(); i++){
        if(v[nod][i] != tt){
            dfs(v[nod][i], nod);
        }
    }
}
void Link(int x, int y) {
    int r1, r2, nod;
    g[x]++;
    g[y]++;
    if(g[x] == 3){
        frst[y] = x;
    }
    if(g[y] == 3){
        frst[x] = y;
    }
    upd(x);
    upd(y);
    r1 = rad(x);
    r2 = rad(y);
    m++;
    if(r1 != r2){
        nrcomp--;
        if(r[r1] < r[r2]){
            r[r1] += r[r2];
            r[r2] = r1;
        }
        else{
            r[r2] += r[r1];
            r[r1] = r2;
        }
    }
    else{
        nrcic++;
        if(nrcic == 1){
            t[x] = -1;
            dfs(x, -1);
            nod = y;
            while(nod != -1){
                viz[nod] = 1;
                nod = t[nod];
                num++;
            }
        }
    }
    v[x].push_back(y);
    v[y].push_back(x);
}

int CountCritical() {
    if(nr4 > 1){
        return 0;
    }
    if(nr4 == 1){
        return verif(g4[0]);
    }
    if(nr3 > 3){
        return 0;
    }
    if(nr3 != 0){
        int nr = 0;
        for(int i = 0; i < nr3; i++){
            nr += verif(g3[i]);
            int nod = g3[i];
            for(int j = 0; j < v[nod].size(); j++){
                if(frst[ v[nod][j] ] == nod && g[ v[nod][j] ] < 3){
                    nr += verif(v[nod][j]);
                }
            }
        }
        return nr;
    }
    if(nrcic > 1){
        return 0;
    }
    if(nrcic == 1){
        return num;
    }
    return n;
}

Compilation message

rings.cpp: In function 'void upd(int)':
rings.cpp:22:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i < v[nod].size(); i++){
                        ~~^~~~~~~~~~~~~~~
rings.cpp: In function 'int verif(int)':
rings.cpp:38:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < v[nod].size(); i++){
                    ~~^~~~~~~~~~~~~~~
rings.cpp:34:9: warning: unused variable 'i' [-Wunused-variable]
     int i, n3 = 0;
         ^
rings.cpp: In function 'void dfs(int, int)':
rings.cpp:59:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < v[nod].size(); i++){
                    ~~^~~~~~~~~~~~~~~
rings.cpp: In function 'int CountCritical()':
rings.cpp:123:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int j = 0; j < v[nod].size(); j++){
                            ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 23808 KB Output is correct
2 Correct 20 ms 24064 KB Output is correct
3 Correct 22 ms 24064 KB Output is correct
4 Correct 19 ms 23936 KB Output is correct
5 Correct 22 ms 24064 KB Output is correct
6 Correct 22 ms 24312 KB Output is correct
7 Correct 18 ms 23936 KB Output is correct
8 Correct 20 ms 24064 KB Output is correct
9 Correct 21 ms 24064 KB Output is correct
10 Correct 20 ms 24192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 437 ms 45176 KB Output is correct
2 Correct 805 ms 56184 KB Output is correct
3 Correct 994 ms 66868 KB Output is correct
4 Correct 1027 ms 67028 KB Output is correct
5 Correct 1038 ms 85112 KB Output is correct
6 Correct 1162 ms 105612 KB Output is correct
7 Correct 978 ms 81032 KB Output is correct
8 Correct 956 ms 73336 KB Output is correct
9 Correct 1029 ms 76660 KB Output is correct
10 Correct 770 ms 77536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 23808 KB Output is correct
2 Correct 20 ms 24064 KB Output is correct
3 Correct 22 ms 24064 KB Output is correct
4 Correct 19 ms 23936 KB Output is correct
5 Correct 22 ms 24064 KB Output is correct
6 Correct 22 ms 24312 KB Output is correct
7 Correct 18 ms 23936 KB Output is correct
8 Correct 20 ms 24064 KB Output is correct
9 Correct 21 ms 24064 KB Output is correct
10 Correct 20 ms 24192 KB Output is correct
11 Incorrect 21 ms 24192 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 23808 KB Output is correct
2 Correct 20 ms 24064 KB Output is correct
3 Correct 22 ms 24064 KB Output is correct
4 Correct 19 ms 23936 KB Output is correct
5 Correct 22 ms 24064 KB Output is correct
6 Correct 22 ms 24312 KB Output is correct
7 Correct 18 ms 23936 KB Output is correct
8 Correct 20 ms 24064 KB Output is correct
9 Correct 21 ms 24064 KB Output is correct
10 Correct 20 ms 24192 KB Output is correct
11 Incorrect 21 ms 24192 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 23808 KB Output is correct
2 Correct 20 ms 24064 KB Output is correct
3 Correct 22 ms 24064 KB Output is correct
4 Correct 19 ms 23936 KB Output is correct
5 Correct 22 ms 24064 KB Output is correct
6 Correct 22 ms 24312 KB Output is correct
7 Correct 18 ms 23936 KB Output is correct
8 Correct 20 ms 24064 KB Output is correct
9 Correct 21 ms 24064 KB Output is correct
10 Correct 20 ms 24192 KB Output is correct
11 Correct 437 ms 45176 KB Output is correct
12 Correct 805 ms 56184 KB Output is correct
13 Correct 994 ms 66868 KB Output is correct
14 Correct 1027 ms 67028 KB Output is correct
15 Correct 1038 ms 85112 KB Output is correct
16 Correct 1162 ms 105612 KB Output is correct
17 Correct 978 ms 81032 KB Output is correct
18 Correct 956 ms 73336 KB Output is correct
19 Correct 1029 ms 76660 KB Output is correct
20 Correct 770 ms 77536 KB Output is correct
21 Incorrect 21 ms 24192 KB Output isn't correct
22 Halted 0 ms 0 KB -