Submission #49525

# Submission time Handle Problem Language Result Execution time Memory
49525 2018-05-30T07:26:12 Z ho94949 Parachute rings (IOI12_rings) C++17
100 / 100
1706 ms 120472 KB
#include<vector>
#include<algorithm>
using namespace std;

const int MAXN = 1010101;

struct UF
{
    int ufd[MAXN], N;
    UF(){}
    UF(int n): N(n)
    {
        for(int i=0; i<n; ++i) ufd[i] = i;
    }
    int Find(int a)
    {
        if(a==ufd[a]) return a;
        return ufd[a] = Find(ufd[a]);
    }
    bool Union(int a, int b)
    {
        a = Find(a); b = Find(b);
        if(a==b) return false;
        ufd[a] = b; return true;
    }
};
struct DAT
{
    UF uf; int deg[MAXN]; int N; int numcyc; int cyclen; bool ovdeg;
    DAT(){}
    DAT(int n): N(n), uf(n), numcyc(0), cyclen(0), ovdeg(0)
    {
        for(int i=0; i<N; ++i) deg[i] = 0;
    }
    void Add(int a, int b)
    {
        deg[a]++; deg[b]++;
        if(deg[a] >= 3 || deg[b] >= 3) ovdeg=true;
        if(!uf.Union(a, b))
            if((++numcyc)==1)
                for(int i=0; i<N; ++i)
                    if(uf.Find(i) == uf.Find(a))
                        ++cyclen;
    }
};
DAT global;
int N, M;
pair<int, int> EList[MAXN];
vector<int> conn[MAXN];
int deg[MAXN], ovdeg;
vector<pair<DAT, int> > datas;

void Init(int _N)
{
    N = _N; M = 0; ovdeg = 0;
    DAT d(N); global = d;
}

DAT makeDAT(int x)
{
    DAT d(N);
    for(int i=0; i<M; ++i)
        if(EList[i].first != x && EList[i].second != x)
            d.Add(EList[i].first, EList[i].second);
    return d;
}

void makeGraph()
{
    for(int i=0; i<N; ++i)
    {
        int cnt = (deg[i] >= 3)?1:0;
        for(auto x: conn[i])
            if(deg[x] == 3) ++cnt;
        if(cnt == ovdeg)
            datas.emplace_back(makeDAT(i), i);
    }
}

void Link(int A, int B)
{
    if(ovdeg && datas.size() == 0) return;
    EList[M++] = make_pair(A, B);
    deg[A]++; deg[B]++;
    conn[A].push_back(B);
    conn[B].push_back(A);
    
    int povdeg = ovdeg;
    if(deg[A] == 3) ovdeg++;
    if(deg[B] == 3) ovdeg++;
    if(povdeg == 0 && ovdeg != 0)
        makeGraph();
    else
    {
        if(ovdeg == 0)
            global.Add(A, B);
        else
            for(int i=0; i<datas.size(); ++i)
            {
                if(A!=datas[i].second && B != datas[i].second)
                    datas[i].first.Add(A, B);
                if(datas[i].first.numcyc != 0 || datas[i].first.ovdeg)
                {
                    datas.erase(datas.begin()+i);
                    --i;
                }
            }
    }
}

int CountCritical()
{
    if(ovdeg == 0)
    {
        if(global.numcyc == 0) return N;
        if(global.numcyc == 1) return global.cyclen;
        return 0;
    }
    else
    {
        int cnt = 0;
        for(const auto& x: datas)
            if(x.first.numcyc==0 && !x.first.ovdeg) ++cnt;
        return cnt;
    }
}













Compilation message

rings.cpp: In constructor 'DAT::DAT(int)':
rings.cpp:29:31: warning: 'DAT::N' will be initialized after [-Wreorder]
     UF uf; int deg[MAXN]; int N; int numcyc; int cyclen; bool ovdeg;
                               ^
rings.cpp:29:8: warning:   'UF DAT::uf' [-Wreorder]
     UF uf; int deg[MAXN]; int N; int numcyc; int cyclen; bool ovdeg;
        ^~
rings.cpp:31:5: warning:   when initialized here [-Wreorder]
     DAT(int n): N(n), uf(n), numcyc(0), cyclen(0), ovdeg(0)
     ^~~
rings.cpp: In function 'void Link(int, int)':
rings.cpp:98:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int i=0; i<datas.size(); ++i)
                          ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 31 ms 31992 KB Output is correct
2 Correct 82 ms 71736 KB Output is correct
3 Correct 82 ms 71788 KB Output is correct
4 Correct 31 ms 71788 KB Output is correct
5 Correct 33 ms 71788 KB Output is correct
6 Correct 33 ms 71788 KB Output is correct
7 Correct 84 ms 71868 KB Output is correct
8 Correct 31 ms 71868 KB Output is correct
9 Correct 79 ms 71900 KB Output is correct
10 Correct 86 ms 71940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 549 ms 71940 KB Output is correct
2 Correct 1151 ms 104536 KB Output is correct
3 Correct 386 ms 104536 KB Output is correct
4 Correct 1368 ms 104536 KB Output is correct
5 Correct 1406 ms 104536 KB Output is correct
6 Correct 1309 ms 104536 KB Output is correct
7 Correct 383 ms 104536 KB Output is correct
8 Correct 1524 ms 114332 KB Output is correct
9 Correct 1706 ms 120472 KB Output is correct
10 Correct 968 ms 120472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 31992 KB Output is correct
2 Correct 82 ms 71736 KB Output is correct
3 Correct 82 ms 71788 KB Output is correct
4 Correct 31 ms 71788 KB Output is correct
5 Correct 33 ms 71788 KB Output is correct
6 Correct 33 ms 71788 KB Output is correct
7 Correct 84 ms 71868 KB Output is correct
8 Correct 31 ms 71868 KB Output is correct
9 Correct 79 ms 71900 KB Output is correct
10 Correct 86 ms 71940 KB Output is correct
11 Correct 80 ms 120472 KB Output is correct
12 Correct 85 ms 120472 KB Output is correct
13 Correct 80 ms 120472 KB Output is correct
14 Correct 78 ms 120472 KB Output is correct
15 Correct 83 ms 120472 KB Output is correct
16 Correct 37 ms 120472 KB Output is correct
17 Correct 82 ms 120472 KB Output is correct
18 Correct 87 ms 120472 KB Output is correct
19 Correct 37 ms 120472 KB Output is correct
20 Correct 85 ms 120472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 31992 KB Output is correct
2 Correct 82 ms 71736 KB Output is correct
3 Correct 82 ms 71788 KB Output is correct
4 Correct 31 ms 71788 KB Output is correct
5 Correct 33 ms 71788 KB Output is correct
6 Correct 33 ms 71788 KB Output is correct
7 Correct 84 ms 71868 KB Output is correct
8 Correct 31 ms 71868 KB Output is correct
9 Correct 79 ms 71900 KB Output is correct
10 Correct 86 ms 71940 KB Output is correct
11 Correct 80 ms 120472 KB Output is correct
12 Correct 85 ms 120472 KB Output is correct
13 Correct 80 ms 120472 KB Output is correct
14 Correct 78 ms 120472 KB Output is correct
15 Correct 83 ms 120472 KB Output is correct
16 Correct 37 ms 120472 KB Output is correct
17 Correct 82 ms 120472 KB Output is correct
18 Correct 87 ms 120472 KB Output is correct
19 Correct 37 ms 120472 KB Output is correct
20 Correct 85 ms 120472 KB Output is correct
21 Correct 52 ms 120472 KB Output is correct
22 Correct 64 ms 120472 KB Output is correct
23 Correct 73 ms 120472 KB Output is correct
24 Correct 127 ms 120472 KB Output is correct
25 Correct 100 ms 120472 KB Output is correct
26 Correct 136 ms 120472 KB Output is correct
27 Correct 120 ms 120472 KB Output is correct
28 Correct 114 ms 120472 KB Output is correct
29 Correct 110 ms 120472 KB Output is correct
30 Correct 103 ms 120472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 31992 KB Output is correct
2 Correct 82 ms 71736 KB Output is correct
3 Correct 82 ms 71788 KB Output is correct
4 Correct 31 ms 71788 KB Output is correct
5 Correct 33 ms 71788 KB Output is correct
6 Correct 33 ms 71788 KB Output is correct
7 Correct 84 ms 71868 KB Output is correct
8 Correct 31 ms 71868 KB Output is correct
9 Correct 79 ms 71900 KB Output is correct
10 Correct 86 ms 71940 KB Output is correct
11 Correct 549 ms 71940 KB Output is correct
12 Correct 1151 ms 104536 KB Output is correct
13 Correct 386 ms 104536 KB Output is correct
14 Correct 1368 ms 104536 KB Output is correct
15 Correct 1406 ms 104536 KB Output is correct
16 Correct 1309 ms 104536 KB Output is correct
17 Correct 383 ms 104536 KB Output is correct
18 Correct 1524 ms 114332 KB Output is correct
19 Correct 1706 ms 120472 KB Output is correct
20 Correct 968 ms 120472 KB Output is correct
21 Correct 80 ms 120472 KB Output is correct
22 Correct 85 ms 120472 KB Output is correct
23 Correct 80 ms 120472 KB Output is correct
24 Correct 78 ms 120472 KB Output is correct
25 Correct 83 ms 120472 KB Output is correct
26 Correct 37 ms 120472 KB Output is correct
27 Correct 82 ms 120472 KB Output is correct
28 Correct 87 ms 120472 KB Output is correct
29 Correct 37 ms 120472 KB Output is correct
30 Correct 85 ms 120472 KB Output is correct
31 Correct 52 ms 120472 KB Output is correct
32 Correct 64 ms 120472 KB Output is correct
33 Correct 73 ms 120472 KB Output is correct
34 Correct 127 ms 120472 KB Output is correct
35 Correct 100 ms 120472 KB Output is correct
36 Correct 136 ms 120472 KB Output is correct
37 Correct 120 ms 120472 KB Output is correct
38 Correct 114 ms 120472 KB Output is correct
39 Correct 110 ms 120472 KB Output is correct
40 Correct 103 ms 120472 KB Output is correct
41 Correct 280 ms 120472 KB Output is correct
42 Correct 713 ms 120472 KB Output is correct
43 Correct 366 ms 120472 KB Output is correct
44 Correct 421 ms 120472 KB Output is correct
45 Correct 546 ms 120472 KB Output is correct
46 Correct 855 ms 120472 KB Output is correct
47 Correct 1170 ms 120472 KB Output is correct
48 Correct 347 ms 120472 KB Output is correct
49 Correct 816 ms 120472 KB Output is correct
50 Correct 888 ms 120472 KB Output is correct
51 Correct 408 ms 120472 KB Output is correct
52 Correct 385 ms 120472 KB Output is correct
53 Correct 321 ms 120472 KB Output is correct
54 Correct 1294 ms 120472 KB Output is correct
55 Correct 1254 ms 120472 KB Output is correct