답안 #350898

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
350898 2021-01-19T09:43:14 Z juggernaut 낙하산 고리들 (IOI12_rings) C++14
0 / 100
4000 ms 23916 KB
#ifndef EVAL
#include"grader.cpp"
#endif
#include<bits/stdc++.h>
using namespace std;
vector<int>g[1000005];
bool on[1000005],vis[1000005];
int n,deg[1000005];
int counter[6];
bool flag;
#define DEBUG(x) cout<<#x<<"="<<x<<"\n"
int cycle_number,cycle_size;
int update_counter(int x,int y){
    counter[min(x,5)]+=y;
}
void go(int v,int p){
    if(on[v])return;
    vis[v]=1;
    for(int to:g[v])if(to!=p){
        if(vis[to]){
            flag=true;
            continue;
        }
        go(to,v);
    }
}
bool check(){
    for(int i=0;i<n;i++)vis[i]=0;
    for(int i=0;i<n;i++){
        if(on[i])continue;
        if(deg[i]>2)return false;
        if(vis[i])continue;
        flag=false;
        go(i,i);
        if(flag)return false;
    }
    return true;
}
void Init(int N){
    n=N;
    counter[0]=n;
}
void Link(int x,int y){
    g[x].push_back(y);
    g[y].push_back(x);
    while(1);
    update_counter(deg[x],-1);
    update_counter(deg[y],-1);
    deg[x]++;
    deg[y]++;
    update_counter(deg[x],+1);
    update_counter(deg[y],+1);
}
int CountCritical(){
    if(counter[4]+counter[5]>0){
        if(counter[4]+counter[5]!=1)return 0;
        for(int i=0;i<n;i++){
            if(deg[i]>3){
                on[i]=true;
                for(auto to:g[i])deg[to]--;
                int cnt=check();
                for(auto to:g[i])deg[to]++;
                on[i]=false;
                return cnt;
            }
        }
    }else if(counter[3]){
        for(int i=0;i<n;i++){
            int cnt=0;
            if(deg[i]==3){
                on[i]=true;
                for(auto to:g[i])deg[to]--;
                cnt+=check();
                for(auto to:g[i])deg[to]++;
                on[i]=false;
                for(int to:g[i]){
                    on[to]=true;
                    for(auto to2:g[to])deg[to2]--;
                    cnt+=check();
                    for(auto to2:g[to])deg[to2]++;
                    on[to]=false;
                }
                return cnt;
            }
        }
    }else if(counter[2]){
        for(int i=0;i<n;i++)vis[i]=0;
        cycle_number=0,cycle_size=0;
        for(int i=0;i<n;i++)
            if(!vis[i]){
                flag=false;
                go(i,i);
                if(flag)cycle_number++;
                else if(!cycle_number)cycle_size=0;
            }
        if(cycle_number==0)return n;
        else if(cycle_number==1)return cycle_size;
        else return 0;
    }else return n;
}
/*
7 13
-1
1 2
-1
0 5
-1
2 0
-1
3 2
-1
3 5
-1
4 3
-1

*/

Compilation message

rings.cpp: In function 'int update_counter(int, int)':
rings.cpp:15:1: warning: no return statement in function returning non-void [-Wreturn-type]
   15 | }
      | ^
rings.cpp: In function 'int CountCritical()':
rings.cpp:100:1: warning: control reaches end of non-void function [-Wreturn-type]
  100 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4014 ms 23788 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4062 ms 23916 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4014 ms 23788 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4014 ms 23788 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4014 ms 23788 KB Time limit exceeded
2 Halted 0 ms 0 KB -