답안 #868671

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
868671 2023-11-01T10:51:45 Z HuyQuang_re_Zero 낙하산 고리들 (IOI12_rings) C++14
100 / 100
1047 ms 129528 KB
#include <bits/stdc++.h>
#define ll long long
#define db long double
#define II pair <ll,ll>
#define III pair <ll,II>
#define IV pair <vector <int>,vector <int> >
#define fst first
#define snd second
#define BIT(x,i) ((x>>i)&1)
#define pi acos(-1)
#define to_radian(x) (x*pi/180.0)
#define to_degree(x) (x*180.0/pi)
#define Log(x) (31-__builtin_clz((int)x))
#define LogLL(x) (63-__builtin_clzll((ll)x))
#define N 1000005
using namespace std;
struct International_Olympiad_in_Informatics
{
    struct DSU
    {
        int r[N];
        int root(int u) { return (u==r[u]) ? u : r[u]=root(r[u]); }
        void Init()
        {
            for(int u=1;u<N;u++) r[u]=u;
        }
        bool connect(int u,int v)
        {
            u=root(u); v=root(v);
            if(u==v) return 0;
            r[u]=v;
            return 1;
        }
    } DS[4];

    vector <II> edge;
    vector <int> candidate,a[N],ok1;
    int n,i,u,v,flag,cnt3,cnt4,int4,deg[N],to_3[N],num[N],n_ring,w_ring,node[N],node3[N],r[N],now[N],step;
    bool have_cycle[N];
    void Init(int _n)
    {
        n=_n;
        for(u=1;u<=n;u++) ok1.push_back(u),r[u]=u,node[u]=1;
    }
    bool check1(int u)
    {
        if(cnt4==2) return 0;
        if(cnt4==1 && deg[u]<4) return 0;
        return (to_3[u]==cnt3);
    }
    void update(int u,int k) { to_3[u]+=k; }
    void Filter(int u,int v)
    {
        vector <int> tg;
        for(int x:candidate)
            if(!((u!=x && v!=x && DS[num[x]].connect(u,v)==0) || check1(x)==0))
                tg.push_back(x);
        candidate=tg;
        return ;
    }

    int root(int u) { return (u==r[u]) ? u : r[u]=root(r[u]); }
    void check_root(int u,int op)
    {
        if(have_cycle[u]==1 && node3[u]==0)
            n_ring+=op,w_ring+=op*node[u];
    }
    void join(int u,int v)
    {
        u=root(u); v=root(v);
        if(u==v)
        {
            check_root(u,-1);
            have_cycle[u]=1;
            check_root(u,1);
            return ;
        }
        check_root(u,-1);
        check_root(v,-1);
        r[u]=v;
        node3[v]+=node3[u];
        node[v]+=node[u];
        have_cycle[v]|=have_cycle[u];
        check_root(v,1);
    }
    void Link(int u,int v)
    {
     //  cerr<<u<<" "<<v<<'\n';
        edge.push_back({ u,v });
        a[u].push_back(v); a[v].push_back(u);
        deg[u]++; deg[v]++;
        cnt3+=(deg[u]==3)+(deg[v]==3);
        cnt4+=(deg[u]==4)+(deg[v]==4);
        update(u,(deg[u]==3)+(deg[v]>=3));
        update(v,(deg[v]==3)+(deg[u]>=3));
        check_root(root(u),-1);
        node3[root(u)]+=(deg[u]==3);
        check_root(root(u),1);
        check_root(root(v),-1);
        node3[root(v)]+=(deg[v]==3);
        check_root(root(v),1);
        join(u,v);
        if(deg[u]==3)
        {
            for(int x:a[u])
                if(x!=v) update(x,1);
        }
        if(deg[v]==3)
        {
            for(int x:a[v])
                if(x!=u) update(x,1);
        }
        if(flag) Filter(u,v);
        else
        {
            if(cnt4==2) { step++; ok1.clear(); }
            if(cnt4==1)
            {
                step++;
                vector <int> tg;
                for(int u:ok1)
                    if(check1(u)) tg.push_back(u),now[u]=step;
                ok1=tg;
            }
            if(deg[u]==3 || deg[v]==3)
            {
                step++;
                vector <int> tg;
                if(deg[u]==3)
                {
                    for(int x:a[u])
                        if(now[x]==step-1 && check1(x)) now[x]=step,tg.push_back(x);
                    if(now[u]==step-1 && check1(u)) now[u]=step,tg.push_back(u);
                }
                if(deg[v]==3)
                {
                    for(int x:a[v])
                        if(now[x]==step-1 && check1(x)) now[x]=step,tg.push_back(x);
                    if(now[v]==step-1 && check1(v)) now[v]=step,tg.push_back(v);
                }
                ok1=tg;
            }



            if(ok1.size()<=4)
            {
                flag=1;
                for(int u:ok1)
                {
                    num[u]=candidate.size();
                    candidate.push_back(u);
                    DS[num[u]].Init();
                }
                for(II x:edge) Filter(x.fst,x.snd);
            }
        }
    }
    int Cal()
    {
        if(n_ring>1) return 0;
        if(n_ring==1)
        {
            if(cnt3>0) return 0;
            return w_ring;
        }
        return (flag==0) ? ok1.size() : candidate.size();
    }
} IOI;


void Init(int _n) { IOI.Init(_n); }
void Link(int u,int v) { IOI.Link(u+1,v+1); }
int CountCritical() { return IOI.Cal(); }
int n,u,v,type,q;
/*
int main()
{
    freopen("rings.inp","r",stdin);
    freopen("rings.out","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin>>n>>q; Init(n);
    while(q--)
    {
        cin>>u;
        if(u>-1) cin>>v,Link(u,v);
        else cout<<CountCritical()<<'\n';
    }
}

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 33112 KB Output is correct
2 Correct 11 ms 50012 KB Output is correct
3 Correct 11 ms 50184 KB Output is correct
4 Correct 6 ms 33116 KB Output is correct
5 Correct 7 ms 33372 KB Output is correct
6 Correct 8 ms 33624 KB Output is correct
7 Correct 10 ms 49756 KB Output is correct
8 Correct 7 ms 33372 KB Output is correct
9 Correct 11 ms 50012 KB Output is correct
10 Correct 12 ms 50128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 272 ms 70508 KB Output is correct
2 Correct 732 ms 107928 KB Output is correct
3 Correct 782 ms 111596 KB Output is correct
4 Correct 828 ms 99760 KB Output is correct
5 Correct 820 ms 112756 KB Output is correct
6 Correct 819 ms 112212 KB Output is correct
7 Correct 773 ms 122192 KB Output is correct
8 Correct 973 ms 126476 KB Output is correct
9 Correct 1047 ms 129528 KB Output is correct
10 Correct 552 ms 110000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 33112 KB Output is correct
2 Correct 11 ms 50012 KB Output is correct
3 Correct 11 ms 50184 KB Output is correct
4 Correct 6 ms 33116 KB Output is correct
5 Correct 7 ms 33372 KB Output is correct
6 Correct 8 ms 33624 KB Output is correct
7 Correct 10 ms 49756 KB Output is correct
8 Correct 7 ms 33372 KB Output is correct
9 Correct 11 ms 50012 KB Output is correct
10 Correct 12 ms 50128 KB Output is correct
11 Correct 12 ms 50008 KB Output is correct
12 Correct 14 ms 50524 KB Output is correct
13 Correct 14 ms 52572 KB Output is correct
14 Correct 12 ms 50104 KB Output is correct
15 Correct 12 ms 50268 KB Output is correct
16 Correct 10 ms 35932 KB Output is correct
17 Correct 13 ms 52416 KB Output is correct
18 Correct 14 ms 52572 KB Output is correct
19 Correct 11 ms 35928 KB Output is correct
20 Correct 14 ms 52472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 33112 KB Output is correct
2 Correct 11 ms 50012 KB Output is correct
3 Correct 11 ms 50184 KB Output is correct
4 Correct 6 ms 33116 KB Output is correct
5 Correct 7 ms 33372 KB Output is correct
6 Correct 8 ms 33624 KB Output is correct
7 Correct 10 ms 49756 KB Output is correct
8 Correct 7 ms 33372 KB Output is correct
9 Correct 11 ms 50012 KB Output is correct
10 Correct 12 ms 50128 KB Output is correct
11 Correct 12 ms 50008 KB Output is correct
12 Correct 14 ms 50524 KB Output is correct
13 Correct 14 ms 52572 KB Output is correct
14 Correct 12 ms 50104 KB Output is correct
15 Correct 12 ms 50268 KB Output is correct
16 Correct 10 ms 35932 KB Output is correct
17 Correct 13 ms 52416 KB Output is correct
18 Correct 14 ms 52572 KB Output is correct
19 Correct 11 ms 35928 KB Output is correct
20 Correct 14 ms 52472 KB Output is correct
21 Correct 20 ms 36952 KB Output is correct
22 Correct 28 ms 39900 KB Output is correct
23 Correct 34 ms 40652 KB Output is correct
24 Correct 47 ms 56788 KB Output is correct
25 Correct 19 ms 54748 KB Output is correct
26 Correct 40 ms 57484 KB Output is correct
27 Correct 45 ms 42148 KB Output is correct
28 Correct 43 ms 58584 KB Output is correct
29 Correct 34 ms 56580 KB Output is correct
30 Correct 41 ms 42576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 33112 KB Output is correct
2 Correct 11 ms 50012 KB Output is correct
3 Correct 11 ms 50184 KB Output is correct
4 Correct 6 ms 33116 KB Output is correct
5 Correct 7 ms 33372 KB Output is correct
6 Correct 8 ms 33624 KB Output is correct
7 Correct 10 ms 49756 KB Output is correct
8 Correct 7 ms 33372 KB Output is correct
9 Correct 11 ms 50012 KB Output is correct
10 Correct 12 ms 50128 KB Output is correct
11 Correct 272 ms 70508 KB Output is correct
12 Correct 732 ms 107928 KB Output is correct
13 Correct 782 ms 111596 KB Output is correct
14 Correct 828 ms 99760 KB Output is correct
15 Correct 820 ms 112756 KB Output is correct
16 Correct 819 ms 112212 KB Output is correct
17 Correct 773 ms 122192 KB Output is correct
18 Correct 973 ms 126476 KB Output is correct
19 Correct 1047 ms 129528 KB Output is correct
20 Correct 552 ms 110000 KB Output is correct
21 Correct 12 ms 50008 KB Output is correct
22 Correct 14 ms 50524 KB Output is correct
23 Correct 14 ms 52572 KB Output is correct
24 Correct 12 ms 50104 KB Output is correct
25 Correct 12 ms 50268 KB Output is correct
26 Correct 10 ms 35932 KB Output is correct
27 Correct 13 ms 52416 KB Output is correct
28 Correct 14 ms 52572 KB Output is correct
29 Correct 11 ms 35928 KB Output is correct
30 Correct 14 ms 52472 KB Output is correct
31 Correct 20 ms 36952 KB Output is correct
32 Correct 28 ms 39900 KB Output is correct
33 Correct 34 ms 40652 KB Output is correct
34 Correct 47 ms 56788 KB Output is correct
35 Correct 19 ms 54748 KB Output is correct
36 Correct 40 ms 57484 KB Output is correct
37 Correct 45 ms 42148 KB Output is correct
38 Correct 43 ms 58584 KB Output is correct
39 Correct 34 ms 56580 KB Output is correct
40 Correct 41 ms 42576 KB Output is correct
41 Correct 166 ms 61256 KB Output is correct
42 Correct 410 ms 98172 KB Output is correct
43 Correct 192 ms 76876 KB Output is correct
44 Correct 524 ms 124580 KB Output is correct
45 Correct 616 ms 113848 KB Output is correct
46 Correct 496 ms 103088 KB Output is correct
47 Correct 680 ms 104884 KB Output is correct
48 Correct 388 ms 98356 KB Output is correct
49 Correct 498 ms 101016 KB Output is correct
50 Correct 553 ms 100360 KB Output is correct
51 Correct 217 ms 78784 KB Output is correct
52 Correct 439 ms 111220 KB Output is correct
53 Correct 374 ms 97216 KB Output is correct
54 Correct 853 ms 118052 KB Output is correct
55 Correct 812 ms 124028 KB Output is correct