답안 #103810

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
103810 2019-04-02T18:36:41 Z alexpetrescu 낙하산 고리들 (IOI12_rings) C++14
100 / 100
1805 ms 121040 KB
#include <vector>
#include <utility>

#define x first
#define y second

#define MAXN 1000009

std::vector < std::pair < int, int > > muchii;
std::vector < int > g[MAXN];
int n, ans, stare, t[MAXN], s[MAXN];
struct graf {
    int interzis;
    bool bines;
    int t[MAXN], gr[MAXN];
};
std::vector < graf > grafuri;

int sef(int x, int t[]) {
    if (t[x] == x) return x;
    else return t[x] = sef(t[x], t);
}

inline void baga(graf &a, int x, int y) {
    if (a.bines == 0)
        return ;
    if (x == a.interzis || y == a.interzis)
        return ;
    a.gr[x]++;
    a.gr[y]++;
    if (a.gr[x] >= 3 || a.gr[y] >= 3)
        a.bines = 0;
    x = sef(x, a.t);
    y = sef(y, a.t);
    if (x == y)
        a.bines = 0;
    else
        a.t[x] = y;
}

inline void solve(graf &a) {
    a.bines = 1;
    for (int i = 0; i < n; i++)
        a.t[i] = i, a.gr[i] = 0;
    for (auto &x : muchii)
        baga(a, x.x, x.y);
}

void Init(int N_) {
    n = ans = N_;
    for (int i = 0; i < ans; i++)
        t[i] = i, s[i] = 1;
    stare = 1;
}

void Link(int A, int B) {
    if (stare == 4)
        return ;
    if (stare == 3) {
        ans = 0;
        for (auto &x : grafuri) {
            baga(x, A, B);
            ans += x.bines;
        }
        return ;
    }
    muchii.push_back({A, B});
    g[A].push_back(B);
    g[B].push_back(A);
    if ((int)g[A].size() == 3 || (int)g[B].size() == 3) {
        std::vector < int > noduri;
        if ((int)g[A].size() == 3 && (int)g[B].size() == 3)
            noduri.push_back(A), noduri.push_back(B);
        else {
            if ((int)g[A].size() < 3)
                A = B;
            noduri.push_back(A);
            for (auto &x : g[A])
                noduri.push_back(x);
        }
        stare = 3;
        grafuri.resize(noduri.size());
        for (int i = 0; i < (int)grafuri.size(); i++)
            grafuri[i].interzis = noduri[i];
        ans = 0;
        for (auto &x : grafuri) {
            solve(x);
            ans += x.bines;
        }
        return ;
    }
    if (stare == 1) {
        A = sef(A, t);
        B = sef(B, t);
        if (A == B)
            ans = s[A], stare = 2;
        else
            t[A] = B, s[B] += s[A];
        return ;
    }
    /// stare == 2
    A = sef(A, t);
    B = sef(B, t);
    if (A == B)
        ans = 0, stare = 4;
    else
        t[A] = B, s[B] += s[A];
}

int CountCritical() {
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 23800 KB Output is correct
2 Correct 59 ms 63096 KB Output is correct
3 Correct 58 ms 63096 KB Output is correct
4 Correct 26 ms 23808 KB Output is correct
5 Correct 28 ms 23936 KB Output is correct
6 Correct 27 ms 24192 KB Output is correct
7 Correct 63 ms 62968 KB Output is correct
8 Correct 26 ms 24064 KB Output is correct
9 Correct 59 ms 63096 KB Output is correct
10 Correct 59 ms 63352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 561 ms 48688 KB Output is correct
2 Correct 789 ms 87112 KB Output is correct
3 Correct 344 ms 83960 KB Output is correct
4 Correct 1433 ms 84340 KB Output is correct
5 Correct 1457 ms 84272 KB Output is correct
6 Correct 1426 ms 82640 KB Output is correct
7 Correct 330 ms 83548 KB Output is correct
8 Correct 1466 ms 114388 KB Output is correct
9 Correct 1805 ms 121040 KB Output is correct
10 Correct 1045 ms 81404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 23800 KB Output is correct
2 Correct 59 ms 63096 KB Output is correct
3 Correct 58 ms 63096 KB Output is correct
4 Correct 26 ms 23808 KB Output is correct
5 Correct 28 ms 23936 KB Output is correct
6 Correct 27 ms 24192 KB Output is correct
7 Correct 63 ms 62968 KB Output is correct
8 Correct 26 ms 24064 KB Output is correct
9 Correct 59 ms 63096 KB Output is correct
10 Correct 59 ms 63352 KB Output is correct
11 Correct 62 ms 63240 KB Output is correct
12 Correct 63 ms 63608 KB Output is correct
13 Correct 67 ms 63352 KB Output is correct
14 Correct 55 ms 63096 KB Output is correct
15 Correct 62 ms 63224 KB Output is correct
16 Correct 78 ms 24440 KB Output is correct
17 Correct 53 ms 63224 KB Output is correct
18 Correct 68 ms 63480 KB Output is correct
19 Correct 31 ms 24492 KB Output is correct
20 Correct 63 ms 63608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 23800 KB Output is correct
2 Correct 59 ms 63096 KB Output is correct
3 Correct 58 ms 63096 KB Output is correct
4 Correct 26 ms 23808 KB Output is correct
5 Correct 28 ms 23936 KB Output is correct
6 Correct 27 ms 24192 KB Output is correct
7 Correct 63 ms 62968 KB Output is correct
8 Correct 26 ms 24064 KB Output is correct
9 Correct 59 ms 63096 KB Output is correct
10 Correct 59 ms 63352 KB Output is correct
11 Correct 62 ms 63240 KB Output is correct
12 Correct 63 ms 63608 KB Output is correct
13 Correct 67 ms 63352 KB Output is correct
14 Correct 55 ms 63096 KB Output is correct
15 Correct 62 ms 63224 KB Output is correct
16 Correct 78 ms 24440 KB Output is correct
17 Correct 53 ms 63224 KB Output is correct
18 Correct 68 ms 63480 KB Output is correct
19 Correct 31 ms 24492 KB Output is correct
20 Correct 63 ms 63608 KB Output is correct
21 Correct 41 ms 25588 KB Output is correct
22 Correct 59 ms 26480 KB Output is correct
23 Correct 67 ms 27248 KB Output is correct
24 Correct 85 ms 64104 KB Output is correct
25 Correct 65 ms 63992 KB Output is correct
26 Correct 85 ms 64012 KB Output is correct
27 Correct 98 ms 27888 KB Output is correct
28 Correct 80 ms 63992 KB Output is correct
29 Correct 78 ms 64244 KB Output is correct
30 Correct 103 ms 28624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 23800 KB Output is correct
2 Correct 59 ms 63096 KB Output is correct
3 Correct 58 ms 63096 KB Output is correct
4 Correct 26 ms 23808 KB Output is correct
5 Correct 28 ms 23936 KB Output is correct
6 Correct 27 ms 24192 KB Output is correct
7 Correct 63 ms 62968 KB Output is correct
8 Correct 26 ms 24064 KB Output is correct
9 Correct 59 ms 63096 KB Output is correct
10 Correct 59 ms 63352 KB Output is correct
11 Correct 561 ms 48688 KB Output is correct
12 Correct 789 ms 87112 KB Output is correct
13 Correct 344 ms 83960 KB Output is correct
14 Correct 1433 ms 84340 KB Output is correct
15 Correct 1457 ms 84272 KB Output is correct
16 Correct 1426 ms 82640 KB Output is correct
17 Correct 330 ms 83548 KB Output is correct
18 Correct 1466 ms 114388 KB Output is correct
19 Correct 1805 ms 121040 KB Output is correct
20 Correct 1045 ms 81404 KB Output is correct
21 Correct 62 ms 63240 KB Output is correct
22 Correct 63 ms 63608 KB Output is correct
23 Correct 67 ms 63352 KB Output is correct
24 Correct 55 ms 63096 KB Output is correct
25 Correct 62 ms 63224 KB Output is correct
26 Correct 78 ms 24440 KB Output is correct
27 Correct 53 ms 63224 KB Output is correct
28 Correct 68 ms 63480 KB Output is correct
29 Correct 31 ms 24492 KB Output is correct
30 Correct 63 ms 63608 KB Output is correct
31 Correct 41 ms 25588 KB Output is correct
32 Correct 59 ms 26480 KB Output is correct
33 Correct 67 ms 27248 KB Output is correct
34 Correct 85 ms 64104 KB Output is correct
35 Correct 65 ms 63992 KB Output is correct
36 Correct 85 ms 64012 KB Output is correct
37 Correct 98 ms 27888 KB Output is correct
38 Correct 80 ms 63992 KB Output is correct
39 Correct 78 ms 64244 KB Output is correct
40 Correct 103 ms 28624 KB Output is correct
41 Correct 350 ms 41492 KB Output is correct
42 Correct 753 ms 91740 KB Output is correct
43 Correct 266 ms 75516 KB Output is correct
44 Correct 339 ms 82756 KB Output is correct
45 Correct 464 ms 82148 KB Output is correct
46 Correct 814 ms 74092 KB Output is correct
47 Correct 1253 ms 75624 KB Output is correct
48 Correct 289 ms 79324 KB Output is correct
49 Correct 909 ms 73244 KB Output is correct
50 Correct 888 ms 72812 KB Output is correct
51 Correct 248 ms 74332 KB Output is correct
52 Correct 340 ms 79748 KB Output is correct
53 Correct 371 ms 78328 KB Output is correct
54 Correct 1189 ms 103084 KB Output is correct
55 Correct 499 ms 82688 KB Output is correct