Submission #317385

# Submission time Handle Problem Language Result Execution time Memory
317385 2020-10-29T16:45:25 Z mohamedsobhi777 Parachute rings (IOI12_rings) C++14
20 / 100
4000 ms 1164 KB
#include <bits/stdc++.h>

using namespace std;
int N;
const int cn = 10000;

vector<int> adj[cn];
int deg[cn];
int vis[cn];
int c;
bool bd = 1;
int del;
vector<int> vec;
set<int> th;
int asy = 1;

struct dsu
{
        int fat[cn];
        dsu()
        {
                memset(fat, 0, sizeof fat);
                for (int i = 0; i < N; ++i)
                        fat[i] = i;
        }
        inline int find(int x) { return fat[x] = (x == fat[x] ? x : find(fat[x])); }
        inline bool same(int x, int y) { return find(x) == find(y); }
        void link(int u, int v)
        {
                u = find(u);
                v = find(v);
                if (fat[u] != v)
                        fat[u] = v;
        }
} d1;

void dfs(int x, int p)
{
        vis[x] = c;
        int ch = (p != x);
        vec.push_back(x);
        for (auto u : adj[x])
        {
                if (u == p || del == u)
                        continue;
                if (vis[u] == c)
                        bd = 0;
                else
                        dfs(u, x), ++ch;
        }
        if (ch > 2)
                bd = 0;
}
set<int> bigs;

bool check(int i)
{
        del = i;
        for (auto u : adj[i])
        {
                deg[u]--;
                deg[i]--;
        }
        bool ok = 1;
        vec.clear();
        for (int j = 0; j < N; ++j)
        {
                if (vis[j] != c && i != j)
                {
                        bd = 1;
                        dfs(j, j);
                        ok &= bd;
                }
        }

        for (auto u : adj[i])
        {
                deg[u]++;
                deg[i]++;
        }
        return ok;
}

int brute()
{

        if (th.size() > 2)
                return 0;
        if (asy)
                return N;
        int ret = 0;
        for (int i = 0; i < N; ++i)
        {
                ++c;
                if (check(i))
                        ++ret;
        }

        return ret;
}

void Init(int N_)
{

        N = N_;
}
void Link(int A, int B)
{
        adj[A].push_back(B);
        adj[B].push_back(A);
        if (d1.same(A, B))
                asy = 0;
        d1.link(A, B);
        deg[A]++;
        deg[B]++;
        if (deg[A] > 3)
                bigs.insert(A);
        if (deg[B] > 3)
                bigs.insert(B);
        if (deg[A] == 3)
        {
                th.insert(A);
        }
        if (deg[B] == 3)
        {
                th.insert(B);
        }
}

int CountCritical()
{
        if (bigs.size() > 1)
                return 0;
        return brute();
        return N;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 640 KB Output is correct
2 Correct 494 ms 944 KB Output is correct
3 Correct 745 ms 1016 KB Output is correct
4 Correct 26 ms 640 KB Output is correct
5 Correct 254 ms 920 KB Output is correct
6 Correct 791 ms 1164 KB Output is correct
7 Correct 1 ms 640 KB Output is correct
8 Correct 397 ms 836 KB Output is correct
9 Correct 767 ms 1144 KB Output is correct
10 Correct 759 ms 964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 640 KB Output is correct
2 Correct 494 ms 944 KB Output is correct
3 Correct 745 ms 1016 KB Output is correct
4 Correct 26 ms 640 KB Output is correct
5 Correct 254 ms 920 KB Output is correct
6 Correct 791 ms 1164 KB Output is correct
7 Correct 1 ms 640 KB Output is correct
8 Correct 397 ms 836 KB Output is correct
9 Correct 767 ms 1144 KB Output is correct
10 Correct 759 ms 964 KB Output is correct
11 Execution timed out 4061 ms 924 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 640 KB Output is correct
2 Correct 494 ms 944 KB Output is correct
3 Correct 745 ms 1016 KB Output is correct
4 Correct 26 ms 640 KB Output is correct
5 Correct 254 ms 920 KB Output is correct
6 Correct 791 ms 1164 KB Output is correct
7 Correct 1 ms 640 KB Output is correct
8 Correct 397 ms 836 KB Output is correct
9 Correct 767 ms 1144 KB Output is correct
10 Correct 759 ms 964 KB Output is correct
11 Execution timed out 4061 ms 924 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 640 KB Output is correct
2 Correct 494 ms 944 KB Output is correct
3 Correct 745 ms 1016 KB Output is correct
4 Correct 26 ms 640 KB Output is correct
5 Correct 254 ms 920 KB Output is correct
6 Correct 791 ms 1164 KB Output is correct
7 Correct 1 ms 640 KB Output is correct
8 Correct 397 ms 836 KB Output is correct
9 Correct 767 ms 1144 KB Output is correct
10 Correct 759 ms 964 KB Output is correct
11 Runtime error 2 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Halted 0 ms 0 KB -