답안 #49521

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
49521 2018-05-30T07:22:00 Z ho94949 낙하산 고리들 (IOI12_rings) C++17
0 / 100
1600 ms 114164 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);
            }
    }
}

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)
                          ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 31992 KB Output is correct
2 Incorrect 81 ms 71696 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 481 ms 71696 KB Output is correct
2 Correct 1110 ms 104672 KB Output is correct
3 Correct 406 ms 104672 KB Output is correct
4 Correct 1293 ms 104672 KB Output is correct
5 Correct 1305 ms 104672 KB Output is correct
6 Correct 1303 ms 104672 KB Output is correct
7 Correct 380 ms 104672 KB Output is correct
8 Incorrect 1600 ms 114164 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 31992 KB Output is correct
2 Incorrect 81 ms 71696 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 31992 KB Output is correct
2 Incorrect 81 ms 71696 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 31992 KB Output is correct
2 Incorrect 81 ms 71696 KB Output isn't correct
3 Halted 0 ms 0 KB -