답안 #1020800

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1020800 2024-07-12T10:07:55 Z anton 낙하산 고리들 (IOI12_rings) C++17
100 / 100
1240 ms 148044 KB
#include<bits/stdc++.h>

using namespace std;


struct DSU{
  vector<int> sz, anc, oc, deg;
  int nbG= 0, nbC= 0, csz = 0, above3 = 0;
  DSU(){};
  DSU(int l){
    sz.resize(l);
    anc.resize(l);
    oc.resize(l);
    deg.resize(l);
    nbG = l;
    for(int i = 0; i<l; i++){
      anc[i] = i;
      sz[i] = 1;
      deg[i] = 0;
    }
    oc[0]= l;
  }


  int c(int u){
    if(anc[u] == u){
      return u;
    }
    int v= c(anc[u]);
    anc[u] = v;
    return v;
  }

  void changeDeg(int u, int d){
    oc[deg[u]]--;
    if(deg[u]>=3){
      above3--;
    }
    deg[u]+=d;
    if(deg[u]>=3){
      above3++;
    }
    oc[deg[u]]++;
  }

  void merge(int a, int b){

    changeDeg(a, +1);
    changeDeg(b, +1);
    a=  c(a);
    b = c(b);
    if(a==b){
      nbC++;
      csz = sz[a];
      return;
    }
    nbG--;

    if(sz[a]<sz[b]){
      swap(a, b);
    }
    
    anc[b]= a;
    sz[a]+=sz[b];
  }
};

struct multiDSU{
  unordered_map<int, DSU> dsus;

  multiDSU(){};
  multiDSU(int l, unordered_set<int>& intresting){
    for(auto e: intresting){
      dsus[e] = DSU(l);
    }
    dsus[-1] = DSU(l);
  }

  void merge(int a, int b){
    for(auto it = dsus.begin(); it!=dsus.end(); ++it){
      if(it->first != a && it->first != b){
        //cerr<<"merging "<<a<<" "<<b<<" "<<it->first<<endl;
        it->second.merge(a, b);
      }
    }
  }
};
const int MAX_N = 1e6;
vector<int> adj[MAX_N];
DSU beginDSU;
multiDSU endDSU;

int N;
int state = 0;
//0 = only 2s
//1 = have a 3 or more
void Init(int _N){
  N = _N;
  beginDSU = DSU(N);
}
void Link(int a, int b){
  if(state == 0){
    beginDSU.merge(a, b);
    adj[a].push_back(b);
    adj[b].push_back(a);
    if(adj[a].size()<3){
      swap(a, b);
    }
    if(adj[a].size() >= 3){
      state = 1;
      unordered_set<int> intresting;
      for(auto o: adj[a]){
        intresting.insert(o);
      }
      intresting.insert(a);
      endDSU = multiDSU(N, intresting);
      for(int i = 0; i<N; i++){
        for(auto e: adj[i]){
          if(i<e){
            endDSU.merge(e, i);
          }
        }
      }
    }
  }
  else{
    endDSU.merge(a, b);
  }
}

int CountCritical(){
  if(state== 0){
    if(beginDSU.nbC == 0){
      return N;
    }
    else if(beginDSU.nbC == 1){
      return beginDSU.csz;
    }
    else{
      return 0;
    }
  }
  else{
    int res= 0;
    for(auto it = endDSU.dsus.begin(); it!=endDSU.dsus.end(); ){
      if(it->first != -1){
        if((it->second.oc[0]-1)*2 + it->second.oc[1] == 2*(it->second.nbG-1) && it->second.above3 == 0){
          res++;
          ++it;
        }
        else{
          it = endDSU.dsus.erase(it);
        }
      }
      else{
        ++it;
      }
    }
    return res;
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 23896 KB Output is correct
2 Correct 5 ms 24412 KB Output is correct
3 Correct 6 ms 24412 KB Output is correct
4 Correct 4 ms 23900 KB Output is correct
5 Correct 5 ms 23900 KB Output is correct
6 Correct 5 ms 24156 KB Output is correct
7 Correct 5 ms 24200 KB Output is correct
8 Correct 5 ms 23896 KB Output is correct
9 Correct 5 ms 24412 KB Output is correct
10 Correct 5 ms 24412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 199 ms 48204 KB Output is correct
2 Correct 805 ms 112976 KB Output is correct
3 Correct 1022 ms 118328 KB Output is correct
4 Correct 544 ms 70816 KB Output is correct
5 Correct 612 ms 70736 KB Output is correct
6 Correct 529 ms 69712 KB Output is correct
7 Correct 1008 ms 118460 KB Output is correct
8 Correct 1096 ms 137852 KB Output is correct
9 Correct 1240 ms 148044 KB Output is correct
10 Correct 400 ms 68952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 23896 KB Output is correct
2 Correct 5 ms 24412 KB Output is correct
3 Correct 6 ms 24412 KB Output is correct
4 Correct 4 ms 23900 KB Output is correct
5 Correct 5 ms 23900 KB Output is correct
6 Correct 5 ms 24156 KB Output is correct
7 Correct 5 ms 24200 KB Output is correct
8 Correct 5 ms 23896 KB Output is correct
9 Correct 5 ms 24412 KB Output is correct
10 Correct 5 ms 24412 KB Output is correct
11 Correct 6 ms 24412 KB Output is correct
12 Correct 8 ms 25216 KB Output is correct
13 Correct 8 ms 24924 KB Output is correct
14 Correct 5 ms 24924 KB Output is correct
15 Correct 7 ms 25688 KB Output is correct
16 Correct 7 ms 24444 KB Output is correct
17 Correct 7 ms 24924 KB Output is correct
18 Correct 7 ms 25880 KB Output is correct
19 Correct 7 ms 24412 KB Output is correct
20 Correct 11 ms 25164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 23896 KB Output is correct
2 Correct 5 ms 24412 KB Output is correct
3 Correct 6 ms 24412 KB Output is correct
4 Correct 4 ms 23900 KB Output is correct
5 Correct 5 ms 23900 KB Output is correct
6 Correct 5 ms 24156 KB Output is correct
7 Correct 5 ms 24200 KB Output is correct
8 Correct 5 ms 23896 KB Output is correct
9 Correct 5 ms 24412 KB Output is correct
10 Correct 5 ms 24412 KB Output is correct
11 Correct 6 ms 24412 KB Output is correct
12 Correct 8 ms 25216 KB Output is correct
13 Correct 8 ms 24924 KB Output is correct
14 Correct 5 ms 24924 KB Output is correct
15 Correct 7 ms 25688 KB Output is correct
16 Correct 7 ms 24444 KB Output is correct
17 Correct 7 ms 24924 KB Output is correct
18 Correct 7 ms 25880 KB Output is correct
19 Correct 7 ms 24412 KB Output is correct
20 Correct 11 ms 25164 KB Output is correct
21 Correct 20 ms 25688 KB Output is correct
22 Correct 28 ms 26716 KB Output is correct
23 Correct 32 ms 27484 KB Output is correct
24 Correct 25 ms 32604 KB Output is correct
25 Correct 20 ms 33372 KB Output is correct
26 Correct 27 ms 32860 KB Output is correct
27 Correct 30 ms 28964 KB Output is correct
28 Correct 24 ms 32348 KB Output is correct
29 Correct 22 ms 33628 KB Output is correct
30 Correct 55 ms 29528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 23896 KB Output is correct
2 Correct 5 ms 24412 KB Output is correct
3 Correct 6 ms 24412 KB Output is correct
4 Correct 4 ms 23900 KB Output is correct
5 Correct 5 ms 23900 KB Output is correct
6 Correct 5 ms 24156 KB Output is correct
7 Correct 5 ms 24200 KB Output is correct
8 Correct 5 ms 23896 KB Output is correct
9 Correct 5 ms 24412 KB Output is correct
10 Correct 5 ms 24412 KB Output is correct
11 Correct 199 ms 48204 KB Output is correct
12 Correct 805 ms 112976 KB Output is correct
13 Correct 1022 ms 118328 KB Output is correct
14 Correct 544 ms 70816 KB Output is correct
15 Correct 612 ms 70736 KB Output is correct
16 Correct 529 ms 69712 KB Output is correct
17 Correct 1008 ms 118460 KB Output is correct
18 Correct 1096 ms 137852 KB Output is correct
19 Correct 1240 ms 148044 KB Output is correct
20 Correct 400 ms 68952 KB Output is correct
21 Correct 6 ms 24412 KB Output is correct
22 Correct 8 ms 25216 KB Output is correct
23 Correct 8 ms 24924 KB Output is correct
24 Correct 5 ms 24924 KB Output is correct
25 Correct 7 ms 25688 KB Output is correct
26 Correct 7 ms 24444 KB Output is correct
27 Correct 7 ms 24924 KB Output is correct
28 Correct 7 ms 25880 KB Output is correct
29 Correct 7 ms 24412 KB Output is correct
30 Correct 11 ms 25164 KB Output is correct
31 Correct 20 ms 25688 KB Output is correct
32 Correct 28 ms 26716 KB Output is correct
33 Correct 32 ms 27484 KB Output is correct
34 Correct 25 ms 32604 KB Output is correct
35 Correct 20 ms 33372 KB Output is correct
36 Correct 27 ms 32860 KB Output is correct
37 Correct 30 ms 28964 KB Output is correct
38 Correct 24 ms 32348 KB Output is correct
39 Correct 22 ms 33628 KB Output is correct
40 Correct 55 ms 29528 KB Output is correct
41 Correct 116 ms 43856 KB Output is correct
42 Correct 454 ms 121940 KB Output is correct
43 Correct 159 ms 110928 KB Output is correct
44 Correct 231 ms 110928 KB Output is correct
45 Correct 336 ms 121180 KB Output is correct
46 Correct 348 ms 74836 KB Output is correct
47 Correct 482 ms 75788 KB Output is correct
48 Correct 206 ms 118912 KB Output is correct
49 Correct 368 ms 75440 KB Output is correct
50 Correct 443 ms 74836 KB Output is correct
51 Correct 156 ms 98132 KB Output is correct
52 Correct 202 ms 93264 KB Output is correct
53 Correct 199 ms 118356 KB Output is correct
54 Correct 707 ms 126764 KB Output is correct
55 Correct 352 ms 106888 KB Output is correct