답안 #988774

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
988774 2024-05-26T03:26:44 Z huutuan 낙하산 고리들 (IOI12_rings) C++14
0 / 100
1078 ms 175284 KB
#include <bits/stdc++.h>

using namespace std;

struct DSU{
   int n, check, idx, cnt, mxdeg;
   vector<int> lab, deg;
   void init(int _n){
      n=_n; check=1; idx=-1; cnt=0; mxdeg=0;
      lab.assign(n+1, -1);
      deg.assign(n+1, 0);
   }
   int find_set(int u){
      return lab[u]<0?u:lab[u]=find_set(lab[u]);
   }
   void union_sets(int u, int v){
      ++deg[u], ++deg[v]; mxdeg=max({mxdeg, deg[u], deg[v]});
      u=find_set(u); v=find_set(v);
      if (u!=v){
         if (lab[u]>lab[v]) swap(u, v);
         lab[u]+=lab[v];
         lab[v]=u;
         if (idx==v) idx=u;
      }else check=0, idx=u, ++cnt;
   }
} dsu[10], dsu2;

const int N=1e6+10;
int n, deg[N];
set<int> st3, st4;
vector<pair<int, int>> edge;
bool cc;
vector<int> cand, g[N];

void Init(int N_) {
   n=N_;
   dsu2.init(n);
}

void add_cand(int u){
   if (find(cand.begin(), cand.end(), u)!=cand.end()) return;
   int id=cand.size();
   cand.push_back(u);
   if (id<10){
      dsu[id].init(n+1);
      for (auto &i:edge) if (i.first!=u && i.second!=u) dsu[id].union_sets(i.first, i.second);
   }
}

void Link(int u, int v) {
   ++u; ++v;
   edge.emplace_back(u, v);
   if ((int)cand.size()<=10){
      for (int i=0; i<(int)cand.size(); ++i){
         if (u==cand[i] || v==cand[i]) continue;
         dsu[i].union_sets(u, v);
      }
   }
   st3.erase(u); st3.erase(v);
   ++deg[u]; ++deg[v];
   g[u].push_back(v);
   g[v].push_back(u);
   if (deg[u]==3) st3.insert(u);
   if (deg[v]==3) st3.insert(v);
   if (deg[u]==4) st4.insert(u);
   if (deg[v]==4) st4.insert(v);
   if (deg[u]<deg[v]) swap(u, v);
   if ((int)st3.size()+(int)st4.size()<=10){
      for (int u:st4) add_cand(u);
      for (int u:st3){
         add_cand(u);
         for (int v:g[u]) add_cand(v);
      }
   }
}

int CountCritical() {
   if (st3.empty() && st4.empty()){
      if (dsu2.check) return n;
      if (dsu2.cnt==1) return -dsu2.lab[dsu2.idx];
      return 0;
   }
   int ans=0;
   for (int i=0; i<(int)cand.size(); ++i){
      ans+=dsu[i].check && dsu[i].mxdeg<=2;
   }
   return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 25180 KB Output is correct
2 Correct 5 ms 25436 KB Output is correct
3 Correct 7 ms 25692 KB Output is correct
4 Incorrect 5 ms 25180 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 163 ms 58448 KB Output is correct
2 Correct 532 ms 101168 KB Output is correct
3 Incorrect 1078 ms 175284 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 25180 KB Output is correct
2 Correct 5 ms 25436 KB Output is correct
3 Correct 7 ms 25692 KB Output is correct
4 Incorrect 5 ms 25180 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 25180 KB Output is correct
2 Correct 5 ms 25436 KB Output is correct
3 Correct 7 ms 25692 KB Output is correct
4 Incorrect 5 ms 25180 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 25180 KB Output is correct
2 Correct 5 ms 25436 KB Output is correct
3 Correct 7 ms 25692 KB Output is correct
4 Incorrect 5 ms 25180 KB Output isn't correct
5 Halted 0 ms 0 KB -