Submission #49526

# Submission time Handle Problem Language Result Execution time Memory
49526 2018-05-30T07:41:56 Z ho94949 Parachute rings (IOI12_rings) C++17
100 / 100
1663 ms 120380 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
        return datas.size();
}

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 30 ms 31992 KB Output is correct
2 Correct 86 ms 71696 KB Output is correct
3 Correct 81 ms 71716 KB Output is correct
4 Correct 31 ms 71716 KB Output is correct
5 Correct 32 ms 71716 KB Output is correct
6 Correct 34 ms 71716 KB Output is correct
7 Correct 77 ms 71716 KB Output is correct
8 Correct 33 ms 71716 KB Output is correct
9 Correct 78 ms 71856 KB Output is correct
10 Correct 83 ms 71856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 449 ms 71856 KB Output is correct
2 Correct 1183 ms 104680 KB Output is correct
3 Correct 389 ms 104680 KB Output is correct
4 Correct 1362 ms 104680 KB Output is correct
5 Correct 1386 ms 104680 KB Output is correct
6 Correct 1395 ms 104680 KB Output is correct
7 Correct 367 ms 104680 KB Output is correct
8 Correct 1546 ms 114164 KB Output is correct
9 Correct 1663 ms 120380 KB Output is correct
10 Correct 930 ms 120380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 31992 KB Output is correct
2 Correct 86 ms 71696 KB Output is correct
3 Correct 81 ms 71716 KB Output is correct
4 Correct 31 ms 71716 KB Output is correct
5 Correct 32 ms 71716 KB Output is correct
6 Correct 34 ms 71716 KB Output is correct
7 Correct 77 ms 71716 KB Output is correct
8 Correct 33 ms 71716 KB Output is correct
9 Correct 78 ms 71856 KB Output is correct
10 Correct 83 ms 71856 KB Output is correct
11 Correct 81 ms 120380 KB Output is correct
12 Correct 80 ms 120380 KB Output is correct
13 Correct 85 ms 120380 KB Output is correct
14 Correct 77 ms 120380 KB Output is correct
15 Correct 78 ms 120380 KB Output is correct
16 Correct 36 ms 120380 KB Output is correct
17 Correct 82 ms 120380 KB Output is correct
18 Correct 80 ms 120380 KB Output is correct
19 Correct 34 ms 120380 KB Output is correct
20 Correct 88 ms 120380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 31992 KB Output is correct
2 Correct 86 ms 71696 KB Output is correct
3 Correct 81 ms 71716 KB Output is correct
4 Correct 31 ms 71716 KB Output is correct
5 Correct 32 ms 71716 KB Output is correct
6 Correct 34 ms 71716 KB Output is correct
7 Correct 77 ms 71716 KB Output is correct
8 Correct 33 ms 71716 KB Output is correct
9 Correct 78 ms 71856 KB Output is correct
10 Correct 83 ms 71856 KB Output is correct
11 Correct 81 ms 120380 KB Output is correct
12 Correct 80 ms 120380 KB Output is correct
13 Correct 85 ms 120380 KB Output is correct
14 Correct 77 ms 120380 KB Output is correct
15 Correct 78 ms 120380 KB Output is correct
16 Correct 36 ms 120380 KB Output is correct
17 Correct 82 ms 120380 KB Output is correct
18 Correct 80 ms 120380 KB Output is correct
19 Correct 34 ms 120380 KB Output is correct
20 Correct 88 ms 120380 KB Output is correct
21 Correct 52 ms 120380 KB Output is correct
22 Correct 70 ms 120380 KB Output is correct
23 Correct 82 ms 120380 KB Output is correct
24 Correct 128 ms 120380 KB Output is correct
25 Correct 97 ms 120380 KB Output is correct
26 Correct 136 ms 120380 KB Output is correct
27 Correct 85 ms 120380 KB Output is correct
28 Correct 111 ms 120380 KB Output is correct
29 Correct 106 ms 120380 KB Output is correct
30 Correct 95 ms 120380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 31992 KB Output is correct
2 Correct 86 ms 71696 KB Output is correct
3 Correct 81 ms 71716 KB Output is correct
4 Correct 31 ms 71716 KB Output is correct
5 Correct 32 ms 71716 KB Output is correct
6 Correct 34 ms 71716 KB Output is correct
7 Correct 77 ms 71716 KB Output is correct
8 Correct 33 ms 71716 KB Output is correct
9 Correct 78 ms 71856 KB Output is correct
10 Correct 83 ms 71856 KB Output is correct
11 Correct 449 ms 71856 KB Output is correct
12 Correct 1183 ms 104680 KB Output is correct
13 Correct 389 ms 104680 KB Output is correct
14 Correct 1362 ms 104680 KB Output is correct
15 Correct 1386 ms 104680 KB Output is correct
16 Correct 1395 ms 104680 KB Output is correct
17 Correct 367 ms 104680 KB Output is correct
18 Correct 1546 ms 114164 KB Output is correct
19 Correct 1663 ms 120380 KB Output is correct
20 Correct 930 ms 120380 KB Output is correct
21 Correct 81 ms 120380 KB Output is correct
22 Correct 80 ms 120380 KB Output is correct
23 Correct 85 ms 120380 KB Output is correct
24 Correct 77 ms 120380 KB Output is correct
25 Correct 78 ms 120380 KB Output is correct
26 Correct 36 ms 120380 KB Output is correct
27 Correct 82 ms 120380 KB Output is correct
28 Correct 80 ms 120380 KB Output is correct
29 Correct 34 ms 120380 KB Output is correct
30 Correct 88 ms 120380 KB Output is correct
31 Correct 52 ms 120380 KB Output is correct
32 Correct 70 ms 120380 KB Output is correct
33 Correct 82 ms 120380 KB Output is correct
34 Correct 128 ms 120380 KB Output is correct
35 Correct 97 ms 120380 KB Output is correct
36 Correct 136 ms 120380 KB Output is correct
37 Correct 85 ms 120380 KB Output is correct
38 Correct 111 ms 120380 KB Output is correct
39 Correct 106 ms 120380 KB Output is correct
40 Correct 95 ms 120380 KB Output is correct
41 Correct 264 ms 120380 KB Output is correct
42 Correct 675 ms 120380 KB Output is correct
43 Correct 366 ms 120380 KB Output is correct
44 Correct 403 ms 120380 KB Output is correct
45 Correct 625 ms 120380 KB Output is correct
46 Correct 865 ms 120380 KB Output is correct
47 Correct 1197 ms 120380 KB Output is correct
48 Correct 362 ms 120380 KB Output is correct
49 Correct 830 ms 120380 KB Output is correct
50 Correct 863 ms 120380 KB Output is correct
51 Correct 373 ms 120380 KB Output is correct
52 Correct 397 ms 120380 KB Output is correct
53 Correct 321 ms 120380 KB Output is correct
54 Correct 1291 ms 120380 KB Output is correct
55 Correct 1263 ms 120380 KB Output is correct