Submission #317496

# Submission time Handle Problem Language Result Execution time Memory
317496 2020-10-29T20:31:48 Z mohamedsobhi777 Parachute rings (IOI12_rings) C++14
37 / 100
1420 ms 107756 KB
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:10000000")
using namespace std;
int N;
const int cn = 2e6;

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

struct dsu
{
        int fat[cn];
        dsu()
        {
                memset(fat, 0, sizeof fat);
                for (int i = 0; i < cn; ++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);

        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;
}
vector<int> bigs;
vector<int> cyc;
vector<int> now;
int onc[cn];
int prv[cn];

bool check(int i)
{
        del = i;
        for (auto u : adj[i])
        {
                deg[u]--;
                deg[i]--;
        }
        bool ok = 1;
        ++c;
        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 k = 1e3;
int viz[cn];
int tar;
void detect(int x, int p)
{
        memset(prv, -1, sizeof prv);
        ++c;
        queue<int> qu;
        qu.push(x);
        while (qu.size())
        {
                int a = qu.front();
                qu.pop();
                if (a == tar)
                {
                        int cur = tar;
                        while (~cur)
                        {
                                cyc.push_back(cur);
                                onc[cur] = 1;
                                cur = prv[cur];
                        }
                }
                vis[a] = c;
                for (auto u : adj[a])
                {
                        if (u != prv[a])
                        {
                                prv[u] = a;
                                qu.push(u);
                        }
                }
        }
}

int brute()
{
        int ret = 0;
        set<int> uni;

        if (cs > 1 || bigs.size() > 1 || th.size() > 2)
                return 0;
        if (th.size() == 0 && asy)
                return N;
        if (cs == 1 && th.size() == 0)
                return (int)cyc.size();
        if (bigs.size())
        {
                if (asy)
                        return 1;
                return 4;
        }
        int ans1 = 0;
        if (th.size() == 1)
        {
                if (asy)
                        return 1 + (int)adj[*th.begin()].size();
                ++c;
                int a = *th.begin();
                if (cs == 1)
                {
                        ans1 = onc[a];
                        for (auto u : adj[a])
                                ans1 += onc[u];
                        return ans1;
                }
        }
        else if (th.size() == 2)
        {
                int a = th[0];
                int b = th[1];
                if (cs)
                {
                        if (onc[a] + onc[b] == 0)
                                return 0;
                }
                unordered_map<int, int> mp;
                for (auto u : adj[a])
                        mp[u]++;
                for (auto u : adj[b])
                        mp[u]++;
                mp[a]++;
                mp[b]++;
                for (auto u : mp)
                {
                        if ((onc[u.first] || !cs) && u.second == 2)
                                ++ret;
                }
                return ret;
        }
        if (th.size() == 0)
                return N;

        ret = 0;
        for (int i = 0; i < N; ++i)
        {
                ret += check(i);
        }
        return ret + 100;
}

void Init(int N_)
{

        N = N_;
}
void Link(int A, int B)
{

        cs += (d1.same(A, B));
        if (d1.same(A, B) && asy)
        {
                ++c;
                tar = B;
                detect(A, A);
                asy = 0;
        }
        adj[A].push_back(B);
        adj[B].push_back(A);

        d1.link(A, B);
        deg[A]++;
        deg[B]++;
        if (deg[A] == 4)
                bigs.push_back(A);
        if (deg[B] == 4)
                bigs.push_back(B);
        if (deg[A] == 3)
        {
                th.push_back(A);
        }
        if (deg[B] == 3)
        {
                th.push_back(B);
        }
}

int CountCritical()
{
        if (bigs.size() > 1)
                return 0;
        return brute();
        return N;
}

Compilation message

rings.cpp:2: warning: ignoring #pragma comment  [-Wunknown-pragmas]
    2 | #pragma comment(linker, "/STACK:10000000")
      |
# Verdict Execution time Memory Grader output
1 Correct 38 ms 55168 KB Output is correct
2 Correct 40 ms 55420 KB Output is correct
3 Correct 40 ms 55552 KB Output is correct
4 Correct 44 ms 62976 KB Output is correct
5 Correct 46 ms 63096 KB Output is correct
6 Correct 47 ms 63352 KB Output is correct
7 Correct 39 ms 55160 KB Output is correct
8 Correct 47 ms 63224 KB Output is correct
9 Correct 40 ms 55424 KB Output is correct
10 Correct 40 ms 55416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 512 ms 73976 KB Output is correct
2 Correct 993 ms 84344 KB Output is correct
3 Correct 1289 ms 98408 KB Output is correct
4 Correct 1246 ms 102264 KB Output is correct
5 Correct 1265 ms 107176 KB Output is correct
6 Correct 1420 ms 107756 KB Output is correct
7 Correct 1242 ms 101100 KB Output is correct
8 Correct 1176 ms 88920 KB Output is correct
9 Correct 1245 ms 91060 KB Output is correct
10 Correct 879 ms 101368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 55168 KB Output is correct
2 Correct 40 ms 55420 KB Output is correct
3 Correct 40 ms 55552 KB Output is correct
4 Correct 44 ms 62976 KB Output is correct
5 Correct 46 ms 63096 KB Output is correct
6 Correct 47 ms 63352 KB Output is correct
7 Correct 39 ms 55160 KB Output is correct
8 Correct 47 ms 63224 KB Output is correct
9 Correct 40 ms 55424 KB Output is correct
10 Correct 40 ms 55416 KB Output is correct
11 Incorrect 46 ms 63328 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 38 ms 55168 KB Output is correct
2 Correct 40 ms 55420 KB Output is correct
3 Correct 40 ms 55552 KB Output is correct
4 Correct 44 ms 62976 KB Output is correct
5 Correct 46 ms 63096 KB Output is correct
6 Correct 47 ms 63352 KB Output is correct
7 Correct 39 ms 55160 KB Output is correct
8 Correct 47 ms 63224 KB Output is correct
9 Correct 40 ms 55424 KB Output is correct
10 Correct 40 ms 55416 KB Output is correct
11 Incorrect 46 ms 63328 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 38 ms 55168 KB Output is correct
2 Correct 40 ms 55420 KB Output is correct
3 Correct 40 ms 55552 KB Output is correct
4 Correct 44 ms 62976 KB Output is correct
5 Correct 46 ms 63096 KB Output is correct
6 Correct 47 ms 63352 KB Output is correct
7 Correct 39 ms 55160 KB Output is correct
8 Correct 47 ms 63224 KB Output is correct
9 Correct 40 ms 55424 KB Output is correct
10 Correct 40 ms 55416 KB Output is correct
11 Correct 512 ms 73976 KB Output is correct
12 Correct 993 ms 84344 KB Output is correct
13 Correct 1289 ms 98408 KB Output is correct
14 Correct 1246 ms 102264 KB Output is correct
15 Correct 1265 ms 107176 KB Output is correct
16 Correct 1420 ms 107756 KB Output is correct
17 Correct 1242 ms 101100 KB Output is correct
18 Correct 1176 ms 88920 KB Output is correct
19 Correct 1245 ms 91060 KB Output is correct
20 Correct 879 ms 101368 KB Output is correct
21 Incorrect 46 ms 63328 KB Output isn't correct
22 Halted 0 ms 0 KB -