Submission #357216

# Submission time Handle Problem Language Result Execution time Memory
357216 2021-01-24T03:17:25 Z daniel920712 Parachute rings (IOI12_rings) C++14
0 / 100
1579 ms 87312 KB
#include <stdio.h>
#include <stdlib.h>
#include <vector>
using namespace std;
int N;
int who;
vector < int > Next[1000005],tt;
int deg[1000005];
bool have[1000005];
int ok=1;
int x=0,y=0,z=0;
void Init(int N_)
{
    N = N_;
}

void Link(int A, int B)
{
    Next[A].push_back(B);
    Next[B].push_back(A);
    deg[A]++;
    deg[B]++;
}
void F(int here)
{
    y++;
    int t=0;
    have[here]=1;
    for(auto i:Next[here]) if(!have[i]&&i!=who) F(i);
}
int CountCritical()
{
    int ans=0,now=0;
    int i,j;
    tt.clear();
    for(i=0;i<N;i++)
    {
        if(deg[i]>=3)
        {
            tt.push_back(i);
            now++;
        }
    }
    //printf("%d\n",now);
    if(now==0)
    {
        x=y=0;
        ok=1;
        who=i;
        for(j=0;j<N;j++) have[j]=0;
        for(j=0;j<N;j++)
        {
            if(deg[j]==0) have[j]=1;
            if(deg[j]==1&&!have[j]) F(j);
        }
        for(j=0;j<N;j++)
        {

            if(!have[j])
            {
                who=-1;
                x++;
                y=0;
                F(j);
            }
            ans+=x;
        }

        if(x==0) return N;
        if(x==1) return y;
        return 0;
    }
    else if(now==1)
    {
        //printf("bb %d\n",ans);
        for(auto i:tt)
        {
            ok=1;
            who=i;
            for(auto j:Next[i]) deg[j]--;
            for(j=0;j<N;j++) have[j]=0;
            have[i]=1;
            for(j=0;j<N;j++)
            {
                if(deg[j]==0) have[j]=1;
                if(deg[j]==1&&!have[j]) F(j);
                if(deg[j]>=3&&i!=j) ok=0;
            }
            for(j=0;j<N;j++) if(!have[j]) ok=0;
            for(auto j:Next[i]) deg[j]++;
            ans+=ok;
        }
        //printf("aa %d\n",ans);
        if(deg[tt[0]]==3)
        {
            for(auto i:Next[tt[0]])
            {
                ok=1;
                who=i;
                for(auto j:Next[i]) deg[j]--;
                for(j=0;j<N;j++) have[j]=0;
                have[i]=1;
                for(j=0;j<N;j++)
                {
                    if(deg[j]==0) have[j]=1;
                    if(deg[j]==1&&!have[j]) F(j);
                    if(deg[j]>=3&&i!=j) ok=0;
                }
                for(j=0;j<N;j++) if(!have[j]) ok=0;
                for(auto j:Next[i]) deg[j]++;
                //printf("tt %d %d %d\n",i,ok,ans);
                ans+=ok;
                //printf("%d %d %d\n",i,ok,ans);
            }
        }
        return ans;
    }
    else if(now==2)
    {
        for(auto i:tt)
        {
            ok=1;
            who=i;
            for(auto j:Next[i]) deg[j]--;
            for(j=0;j<N;j++) have[j]=0;
            have[i]=1;
            for(j=0;j<N;j++)
            {
                if(deg[j]==0) have[j]=1;
                if(deg[j]==1&&!have[j]) F(j);
                if(deg[j]>=3&&i!=j) ok=0;
            }
            for(j=0;j<N;j++) if(!have[j]) ok=0;
            for(auto j:Next[i]) deg[j]++;
            ans+=ok;
        }
        return ans;
    }
    else return 0;


}

Compilation message

rings.cpp: In function 'void F(int)':
rings.cpp:27:9: warning: unused variable 't' [-Wunused-variable]
   27 |     int t=0;
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23788 KB Output is correct
2 Correct 17 ms 24044 KB Output is correct
3 Correct 19 ms 24132 KB Output is correct
4 Correct 18 ms 23916 KB Output is correct
5 Correct 20 ms 24044 KB Output is correct
6 Correct 18 ms 24172 KB Output is correct
7 Correct 18 ms 23916 KB Output is correct
8 Correct 18 ms 24044 KB Output is correct
9 Correct 19 ms 24044 KB Output is correct
10 Incorrect 18 ms 24044 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 670 ms 46572 KB Output is correct
2 Correct 1050 ms 63780 KB Output is correct
3 Correct 929 ms 69948 KB Output is correct
4 Correct 1317 ms 73688 KB Output is correct
5 Correct 1463 ms 74220 KB Output is correct
6 Correct 1297 ms 87312 KB Output is correct
7 Correct 970 ms 68844 KB Output is correct
8 Correct 1514 ms 70472 KB Output is correct
9 Incorrect 1579 ms 73948 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23788 KB Output is correct
2 Correct 17 ms 24044 KB Output is correct
3 Correct 19 ms 24132 KB Output is correct
4 Correct 18 ms 23916 KB Output is correct
5 Correct 20 ms 24044 KB Output is correct
6 Correct 18 ms 24172 KB Output is correct
7 Correct 18 ms 23916 KB Output is correct
8 Correct 18 ms 24044 KB Output is correct
9 Correct 19 ms 24044 KB Output is correct
10 Incorrect 18 ms 24044 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23788 KB Output is correct
2 Correct 17 ms 24044 KB Output is correct
3 Correct 19 ms 24132 KB Output is correct
4 Correct 18 ms 23916 KB Output is correct
5 Correct 20 ms 24044 KB Output is correct
6 Correct 18 ms 24172 KB Output is correct
7 Correct 18 ms 23916 KB Output is correct
8 Correct 18 ms 24044 KB Output is correct
9 Correct 19 ms 24044 KB Output is correct
10 Incorrect 18 ms 24044 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23788 KB Output is correct
2 Correct 17 ms 24044 KB Output is correct
3 Correct 19 ms 24132 KB Output is correct
4 Correct 18 ms 23916 KB Output is correct
5 Correct 20 ms 24044 KB Output is correct
6 Correct 18 ms 24172 KB Output is correct
7 Correct 18 ms 23916 KB Output is correct
8 Correct 18 ms 24044 KB Output is correct
9 Correct 19 ms 24044 KB Output is correct
10 Incorrect 18 ms 24044 KB Output isn't correct