Submission #350861

# Submission time Handle Problem Language Result Execution time Memory
350861 2021-01-19T09:21:23 Z talant117408 Parachute rings (IOI12_rings) C++17
0 / 100
4000 ms 72052 KB
#include <bits/stdc++.h>
#ifndef EVAL
#include "grader.cpp"
#endif

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define OK cout << "OK" << endl;

int n;
vector <vector <int>> graph;
int timer, special[1000007], cycles, tin[1000007];
int used[1000007];
vector <int> to_be;
set <pii> st;

void dfs(int v, int p = -1){
    tin[v] = ++timer;
    st.insert(mp(tin[v], v));
    used[v] = 1;
    for(auto to : graph[v]){
        if(p == to) continue;
        if(used[to] == 1){
            cycles++;
            auto it = (st.lb(mp(tin[to], to)));
            map <int, bool> t;
            for(auto iter = it; iter != st.end(); iter++){
                t[(*iter).second] = 1;
            }
            vector <int> ss;
            for(auto iter = it; iter != st.end(); iter++){
                for(auto to2 : graph[(*iter).second]){
                    if(!t.count(to2)){
                        ss.pb(to2);
                    }
                }
            }
            if(sz(ss) == 1)
                to_be.pb(ss[0]);
        }
        else if(!used[to]){
            dfs(to, v);
        }
    }
    used[v] = 2;
    st.erase(st.find(mp(tin[v], v)));
}

void Init(int N) {
    n = N;
    graph.resize(n);
}

void Link(int A, int B) {
    graph[A].pb(B);
    graph[B].pb(A);
}

int CountCritical(){
    /*timer = cnt = 0;
    for(int i = 0; i < n; i++){
        used[i] = 0;
        tin[i] = fup[i] = 0;
    }
    
    vector <int> comps;
    for(int i = 0; i < n; i++){
        if(!used[i]){
            dfs(i);
            comps.pb(in_cmp);
            in_cmp = 0;
        }
    }
    
    if(sz(comps) > 2){
        return n;
    }
    else if(sz(comps) == 2){
        return (comps[0] > 1 ? comps[0] : 0)+(comps[1] > 1 ? comps[1] : 0);
    }*/
    
    for(int i = 0; i < n; i++){
        used[i] = 0;
        special[i] = 0;
        tin[i] = 0;
    }
    
    for(int i = 0; i < n; i++){
        if(!used[i]){
            cycles = timer = 0;
            dfs(i);
            if(cycles == 1 && sz(to_be) == 1){
                special[to_be.back()]++;
            }
            to_be.clear();
            st.clear();
        }
    }
    
    int initial = 0;
    for(int i = 0; i < n; i++){
        if(sz(graph[i]) > 2) initial++;
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(special[i]) continue;
        int tmp = initial - (sz(graph[i]) > 2 ? 1 : 0);
        for(auto to : graph[i]){
            if(sz(graph[to]) == 3) tmp--;
        }
        if(!tmp){
            ans++;
        }
    }
    
    return ans;
}
/*
7 13
-1
1 2
-1
0 5
-1
2 0
-1
3 2
-1
3 5
-1
4 3
-1
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 4 ms 620 KB Output is correct
3 Correct 3 ms 748 KB Output is correct
4 Incorrect 1 ms 492 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 657 ms 35180 KB Output is correct
2 Correct 1212 ms 55020 KB Output is correct
3 Execution timed out 4018 ms 72052 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 4 ms 620 KB Output is correct
3 Correct 3 ms 748 KB Output is correct
4 Incorrect 1 ms 492 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 4 ms 620 KB Output is correct
3 Correct 3 ms 748 KB Output is correct
4 Incorrect 1 ms 492 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 4 ms 620 KB Output is correct
3 Correct 3 ms 748 KB Output is correct
4 Incorrect 1 ms 492 KB Output isn't correct
5 Halted 0 ms 0 KB -