답안 #350322

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
350322 2021-01-19T05:00:36 Z juggernaut 낙하산 고리들 (IOI12_rings) C++14
55 / 100
4000 ms 74220 KB
#include<bits/stdc++.h>
using namespace std;
vector<int>g[1000005];
bool on[1000005],vis[1000005];
int n,deg[1000005],linker;
bool dfs(int v,int p){
    bool flag=false;
    vis[v]=true;
    for(int to:g[v])if(to!=p){
        if(on[to])continue;
        if(flag)return false;
        if(vis[to])return false;
        if(!dfs(to,v))return false;
        flag=true;
    }
    return true;
}
void dfs2(int v){
    linker++;
    vis[v]=1;
    for(int to:g[v])if(!vis[to])dfs2(to);
}
bool check(){
    for(int i=0;i<n;i++)vis[i]=0;
    for(int i=0;i<n;i++)if(!on[i]&&!vis[i]&&deg[i]<2)if(!dfs(i,i))return false;
    for(int i=0;i<n;i++)if(!vis[i]&&!on[i])return false;
    return true;
}
void Init(int N){n=N;}
void Link(int x,int y){
    g[x].push_back(y);
    g[y].push_back(x);
    deg[x]++;
    deg[y]++;
}
int CountCritical(){
    int mx=-1,cnt=0;
    for(int i=0;i<n;i++)
        if(deg[i]>mx){
            mx=deg[i];
            cnt=1;
        }else if(deg[i]==mx)cnt++;
    if(mx>=4){
        if(cnt!=1)return 0;
        cnt=0;
        for(int i=0;i<n;i++){
            if(deg[i]==mx){
                on[i]=true;
                for(auto to:g[i])deg[to]--;
                cnt+=check();
                for(auto to:g[i])deg[to]++;
                on[i]=false;
            }
        }
        return cnt;
    }else if(mx<2)return n;
    else if(mx==2){
        for(int i=0;i<n;i++)vis[i]=0;
        for(int i=0;i<n;i++)if(!vis[i]&&deg[i]<2)dfs(i,i);
        bool flag=false;
        for(int i=0;i<n;i++)if(!vis[i]){
            if(flag)return 0;
            linker=0;
            dfs2(i);
            flag=true;
        }
        if(flag)return linker;
        return n;
    }else if(mx==3){
        for(int i=0;i<n;i++){
            cnt=0;
            if(mx==deg[i]){
                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;
            }
        }
    }
}

Compilation message

rings.cpp: In function 'int CountCritical()':
rings.cpp:89:1: warning: control reaches end of non-void function [-Wreturn-type]
   89 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23788 KB Output is correct
2 Correct 18 ms 24044 KB Output is correct
3 Correct 18 ms 24044 KB Output is correct
4 Correct 17 ms 23916 KB Output is correct
5 Correct 18 ms 24044 KB Output is correct
6 Correct 20 ms 24172 KB Output is correct
7 Correct 17 ms 23916 KB Output is correct
8 Correct 20 ms 24044 KB Output is correct
9 Correct 20 ms 24172 KB Output is correct
10 Correct 19 ms 24044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 552 ms 42816 KB Output is correct
2 Correct 999 ms 53356 KB Output is correct
3 Correct 915 ms 55328 KB Output is correct
4 Correct 1262 ms 60652 KB Output is correct
5 Correct 1253 ms 60780 KB Output is correct
6 Correct 1253 ms 74220 KB Output is correct
7 Correct 908 ms 55464 KB Output is correct
8 Correct 1641 ms 58192 KB Output is correct
9 Correct 1308 ms 60984 KB Output is correct
10 Correct 694 ms 60160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23788 KB Output is correct
2 Correct 18 ms 24044 KB Output is correct
3 Correct 18 ms 24044 KB Output is correct
4 Correct 17 ms 23916 KB Output is correct
5 Correct 18 ms 24044 KB Output is correct
6 Correct 20 ms 24172 KB Output is correct
7 Correct 17 ms 23916 KB Output is correct
8 Correct 20 ms 24044 KB Output is correct
9 Correct 20 ms 24172 KB Output is correct
10 Correct 19 ms 24044 KB Output is correct
11 Correct 36 ms 24044 KB Output is correct
12 Correct 45 ms 24300 KB Output is correct
13 Correct 61 ms 24300 KB Output is correct
14 Correct 34 ms 24044 KB Output is correct
15 Correct 46 ms 24044 KB Output is correct
16 Correct 45 ms 24300 KB Output is correct
17 Correct 24 ms 24300 KB Output is correct
18 Correct 26 ms 24428 KB Output is correct
19 Correct 44 ms 24300 KB Output is correct
20 Correct 58 ms 24300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23788 KB Output is correct
2 Correct 18 ms 24044 KB Output is correct
3 Correct 18 ms 24044 KB Output is correct
4 Correct 17 ms 23916 KB Output is correct
5 Correct 18 ms 24044 KB Output is correct
6 Correct 20 ms 24172 KB Output is correct
7 Correct 17 ms 23916 KB Output is correct
8 Correct 20 ms 24044 KB Output is correct
9 Correct 20 ms 24172 KB Output is correct
10 Correct 19 ms 24044 KB Output is correct
11 Correct 36 ms 24044 KB Output is correct
12 Correct 45 ms 24300 KB Output is correct
13 Correct 61 ms 24300 KB Output is correct
14 Correct 34 ms 24044 KB Output is correct
15 Correct 46 ms 24044 KB Output is correct
16 Correct 45 ms 24300 KB Output is correct
17 Correct 24 ms 24300 KB Output is correct
18 Correct 26 ms 24428 KB Output is correct
19 Correct 44 ms 24300 KB Output is correct
20 Correct 58 ms 24300 KB Output is correct
21 Execution timed out 4062 ms 24868 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23788 KB Output is correct
2 Correct 18 ms 24044 KB Output is correct
3 Correct 18 ms 24044 KB Output is correct
4 Correct 17 ms 23916 KB Output is correct
5 Correct 18 ms 24044 KB Output is correct
6 Correct 20 ms 24172 KB Output is correct
7 Correct 17 ms 23916 KB Output is correct
8 Correct 20 ms 24044 KB Output is correct
9 Correct 20 ms 24172 KB Output is correct
10 Correct 19 ms 24044 KB Output is correct
11 Correct 552 ms 42816 KB Output is correct
12 Correct 999 ms 53356 KB Output is correct
13 Correct 915 ms 55328 KB Output is correct
14 Correct 1262 ms 60652 KB Output is correct
15 Correct 1253 ms 60780 KB Output is correct
16 Correct 1253 ms 74220 KB Output is correct
17 Correct 908 ms 55464 KB Output is correct
18 Correct 1641 ms 58192 KB Output is correct
19 Correct 1308 ms 60984 KB Output is correct
20 Correct 694 ms 60160 KB Output is correct
21 Correct 36 ms 24044 KB Output is correct
22 Correct 45 ms 24300 KB Output is correct
23 Correct 61 ms 24300 KB Output is correct
24 Correct 34 ms 24044 KB Output is correct
25 Correct 46 ms 24044 KB Output is correct
26 Correct 45 ms 24300 KB Output is correct
27 Correct 24 ms 24300 KB Output is correct
28 Correct 26 ms 24428 KB Output is correct
29 Correct 44 ms 24300 KB Output is correct
30 Correct 58 ms 24300 KB Output is correct
31 Execution timed out 4062 ms 24868 KB Time limit exceeded
32 Halted 0 ms 0 KB -