답안 #63416

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
63416 2018-08-01T18:27:46 Z Vahan 낙하산 고리들 (IOI12_rings) C++17
0 / 100
880 ms 78876 KB
#include<vector>
using namespace std;
vector<int> g[2000000];
int n,u[2000000],q,p;
int sz[2000000],pa[2000000];
void crset(int a)
{
    sz[a]=1;
    pa[a]=a;
}
int getparent(int a)
{
    if(pa[a]==a)
        return a;
    pa[a]=getparent(pa[a]);
    return pa[a];
}
void setunion(int a,int b)
{
    a=pa[a];
    b=pa[b];
    if(a==b)
    {
        q++;
        p+=sz[a];
    }
    if(a>b)
    {
        sz[a]+=sz[b];
        pa[b]=a;
    }
    if(a<b)
    {
        sz[b]+=sz[a];
        pa[a]=b;
    }
}
void dfs(int v)
{
    u[v]=1;
    for(int j=0;j<g[v].size();j++)
    {
        int to=g[v][j];
        if(u[to]==0)
            dfs(to);
    }
}
int stug (int x)
{
    int mq=0;
    for(int i=0;i<n;i++)
    {
        if(i==x)
            continue;
        int qq=0;
        for(int j=0;j<g[i].size();j++)
        {
            int to= g[i][j];
            if(to==x)
                continue;
            qq++;
        }
        if(qq==3)
            return 0;
        if(qq==0)
            mq+=2;
        if(qq==1)
            mq+=1;
    }
    for(int i=0;i<n;i++)
        u[i]=0;
    u[x]=1;
    int xq=0;
    for(int i=0;i<n;i++)
    {
        if(u[i]==0)
        {
            dfs(i);
            xq++;
        }
    }
    if(2*xq==mq)
        return 1;
    else
        return 0;
}
void Init(int N_) {

  n = N_;

}

void Link(int A, int B) {
    g[A].push_back(B);
    g[B].push_back(A);

}

int CountCritical() {
    for(int i=0;i<n;i++)
    {
        if(g[i].size()==4)
        {
            if(stug(i))
                return 1;
            else
                return 0;
        }
    }
    for(int i=0;i<n;i++)
    {
        if(g[i].size()==3)
        {
            p=0;
            if(stug(i))
                p++;
            for(int j=0;j<g[i].size();j++)
            {
                int to=g[i][j];
                if(stug(to))
                    p++;
            }
            return p;
        }
    }
    p=0;
    q=0;
    for(int i=0;i<n;i++)
        crset(i);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<g[i].size();j++)
        {
            int to=g[i][j];
            if(to>i)
                setunion(i,to);
        }
    }
    if(q==1)
        return p;
    if(q>1)
        return 0;
    if(q==0)
        return n;
}

Compilation message

rings.cpp: In function 'void dfs(int)':
rings.cpp:41:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j=0;j<g[v].size();j++)
                 ~^~~~~~~~~~~~
rings.cpp: In function 'int stug(int)':
rings.cpp:56:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0;j<g[i].size();j++)
                     ~^~~~~~~~~~~~
rings.cpp: In function 'int CountCritical()':
rings.cpp:117:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int j=0;j<g[i].size();j++)
                         ~^~~~~~~~~~~~
rings.cpp:132:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0;j<g[i].size();j++)
                     ~^~~~~~~~~~~~
rings.cpp:145:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 47224 KB Output is correct
2 Correct 44 ms 47476 KB Output is correct
3 Incorrect 44 ms 47512 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 473 ms 67852 KB Output is correct
2 Incorrect 880 ms 78876 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 47224 KB Output is correct
2 Correct 44 ms 47476 KB Output is correct
3 Incorrect 44 ms 47512 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 47224 KB Output is correct
2 Correct 44 ms 47476 KB Output is correct
3 Incorrect 44 ms 47512 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 47224 KB Output is correct
2 Correct 44 ms 47476 KB Output is correct
3 Incorrect 44 ms 47512 KB Output isn't correct
4 Halted 0 ms 0 KB -