답안 #317475

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
317475 2020-10-29T18:26:36 Z mohamedsobhi777 낙하산 고리들 (IOI12_rings) C++14
37 / 100
1913 ms 104168 KB
#include <bits/stdc++.h>

using namespace std;
int N;
const int cn = 1e6;

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;
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;
}
set<int> bigs;

bool check(int i)
{
        del = i;
        for (auto u : adj[i])
        {
                deg[u]--;
                deg[i]--;
        }
        bool ok = 1;

        for (int j = 0; j < N; ++j)
        {
                ++c;
                if (vis[j] != c && i != j)
                {
                        bd = 1;
                        dfs(j, j);
                        ok &= bd;
                }
        }

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

vector<int> cyc;
vector<int> now;
int onc[cn];

void detect(int x, int p)
{
        if (vis[x] == c)
        {
                cyc = now;
                for (auto u : now)
                        onc[u] = 1;
                return;
        }
        now.push_back(x);

        vis[x] = c;
        for (auto u : adj[x])
        {
                if (u == p || (int)cyc.size())
                        continue;
                detect(u, x);
        }
        now.pop_back();
}

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 onc[*bigs.begin()];
        }
        int ans1 = 0;
        if (th.size() == 1)
        {
                if (asy)
                        return 1 + (int)adj[*th.begin()].size();
                ++c;
                /*set<int> anss;
                int a = (*th.begin());
                if (check(a))
                {
                        anss.insert(a);
                }
                for (auto u : adj[a])
                {
                        ++c;
                        if (check(u))
                                anss.insert(u);
                }*/
                //ans1 = (int)anss.size();
                //                return (int)anss.size();
        }
        else if (th.size() == 2)
        {

                int a = *th.begin();
                int b = *th.rbegin();
                if (cs)
                {
                        if (onc[a] + onc[b] == 0)
                                return 0;
                }
                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;
        }
        set<int> ass;
        if (th.size() == 0)
                return N;
        else
        {
                for (auto u : adj[*th.begin()])
                        ass.insert(u);
                ass.insert(*th.begin());
        }

        assert(th.size() == 1);
        for (auto i : ass)
        {
                if (onc[i])
                        ++ret;
        }
        if (th.size())
        {
                assert(ret == ans1);
        }
        return ret;
}

void Init(int N_)
{

        N = N_;
}
void Link(int A, int B)
{
        adj[A].push_back(B);
        adj[B].push_back(A);
        cs += (d1.same(A, B));
        if (d1.same(A, B) && asy)
        {
                ++c;
                detect(A, A);
                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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 27776 KB Output is correct
2 Correct 20 ms 27904 KB Output is correct
3 Correct 20 ms 27904 KB Output is correct
4 Correct 21 ms 27904 KB Output is correct
5 Correct 21 ms 28032 KB Output is correct
6 Correct 21 ms 28192 KB Output is correct
7 Correct 20 ms 27776 KB Output is correct
8 Correct 21 ms 27904 KB Output is correct
9 Correct 22 ms 27996 KB Output is correct
10 Correct 21 ms 27912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 484 ms 46144 KB Output is correct
2 Correct 970 ms 56044 KB Output is correct
3 Correct 1913 ms 79444 KB Output is correct
4 Correct 1233 ms 66072 KB Output is correct
5 Correct 1237 ms 72312 KB Output is correct
6 Correct 1332 ms 104168 KB Output is correct
7 Correct 1797 ms 80464 KB Output is correct
8 Correct 1151 ms 60824 KB Output is correct
9 Correct 1244 ms 62880 KB Output is correct
10 Correct 822 ms 65272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 27776 KB Output is correct
2 Correct 20 ms 27904 KB Output is correct
3 Correct 20 ms 27904 KB Output is correct
4 Correct 21 ms 27904 KB Output is correct
5 Correct 21 ms 28032 KB Output is correct
6 Correct 21 ms 28192 KB Output is correct
7 Correct 20 ms 27776 KB Output is correct
8 Correct 21 ms 27904 KB Output is correct
9 Correct 22 ms 27996 KB Output is correct
10 Correct 21 ms 27912 KB Output is correct
11 Runtime error 56 ms 56440 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 27776 KB Output is correct
2 Correct 20 ms 27904 KB Output is correct
3 Correct 20 ms 27904 KB Output is correct
4 Correct 21 ms 27904 KB Output is correct
5 Correct 21 ms 28032 KB Output is correct
6 Correct 21 ms 28192 KB Output is correct
7 Correct 20 ms 27776 KB Output is correct
8 Correct 21 ms 27904 KB Output is correct
9 Correct 22 ms 27996 KB Output is correct
10 Correct 21 ms 27912 KB Output is correct
11 Runtime error 56 ms 56440 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 27776 KB Output is correct
2 Correct 20 ms 27904 KB Output is correct
3 Correct 20 ms 27904 KB Output is correct
4 Correct 21 ms 27904 KB Output is correct
5 Correct 21 ms 28032 KB Output is correct
6 Correct 21 ms 28192 KB Output is correct
7 Correct 20 ms 27776 KB Output is correct
8 Correct 21 ms 27904 KB Output is correct
9 Correct 22 ms 27996 KB Output is correct
10 Correct 21 ms 27912 KB Output is correct
11 Correct 484 ms 46144 KB Output is correct
12 Correct 970 ms 56044 KB Output is correct
13 Correct 1913 ms 79444 KB Output is correct
14 Correct 1233 ms 66072 KB Output is correct
15 Correct 1237 ms 72312 KB Output is correct
16 Correct 1332 ms 104168 KB Output is correct
17 Correct 1797 ms 80464 KB Output is correct
18 Correct 1151 ms 60824 KB Output is correct
19 Correct 1244 ms 62880 KB Output is correct
20 Correct 822 ms 65272 KB Output is correct
21 Runtime error 56 ms 56440 KB Execution killed with signal 11 (could be triggered by violating memory limits)
22 Halted 0 ms 0 KB -