답안 #561483

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
561483 2022-05-12T23:47:04 Z CaroLinda 낙하산 고리들 (IOI12_rings) C++14
0 / 100
721 ms 71904 KB
#include <bits/stdc++.h>

#define all(x) x.begin(),x.end()
#define sz(x) (int)(x.size())

const int MAXN = 1e6+10 ;

using namespace std ;

int N;
bool mem ;
vector<int> adj[MAXN] ;
vector< vector<int> > grafos , dsu ;
vector<int> sumiu ;
vector<bool> melou ;
set<int> s ;

void Init(int N_) {
  N = N_;
}

int find(int idx, int x) { return (dsu[idx][x] == x) ? x : find(idx,dsu[idx][x]) ; }
void join(int idx ,int x, int y){
  x = find(idx, x) ;
  y = find(idx,y ) ;
  if(x ==y  ){
    melou[idx] = true ;
    return ;
  }
  if(rand() % 2 ) swap(x,y);
  dsu[idx][x] = y ;
}

void create(int val, int A, int B){


  sumiu.push_back(val) ;
  melou.push_back(false );
  grafos.push_back(vector<int>(N,0)) ;
  dsu.push_back(vector<int>(N)) ; iota(all(dsu.back()),0) ;

  int idx = sz(sumiu)-1;

  s.insert(val) ;

  for(int i = 0 ; i < N ; i++ ){
    if(i == val ) continue ;
    for(auto e : adj[i]){
      if(e == val ) continue ;
      if(i == A && e == B ) continue ;
      if(i == B && e == A ) continue ;
      if(i > e ) continue ;
      if( (++grafos[idx][i]) > 2 ) melou[idx] = true ;
      join(idx,i,e) ;
    }
  }


}

void Link(int A, int B) {

  //significa que jah achei alguem com 4 ou mais
  if(mem){
    for(int i = 0 ; i < sz(sumiu) ; i++ ){
      if(A == sumiu[i] || B == sumiu[i] ) continue ;
      grafos[i][A]++ ;
      grafos[i][B]++ ;
      if(grafos[i][A] > 2 || grafos[i][B] > 2 ) melou[i] = true ;
    }
    return ;
  }

  adj[A].push_back(B) ;
  adj[B].push_back(A) ;

  if(sz(adj[B]) > sz(adj[A])) swap(A,B) ;

  if(sz(adj[A]) > 3){
    mem = true ;
    grafos.clear() ;
    sumiu.clear() ;
    melou.clear() ;
    dsu.clear() ;
    s.clear() ;
    create(A,-1,-1) ;
    return ;
  }

  for(auto &e : {A,B} ){
    if(sz(adj[e]) == 3){
      if(s.empty()){
        for(auto viz : adj[e]){
          create(viz,A,B) ;
        }
        create(e,A,B) ;
        continue ;
      }
      if(s.empty() ) mem =true ;
      sort(all(adj[e])) ;
      auto it = s.begin() ;
      while(it != s.end()){
        if(find(all(adj[e]) , *it) == adj[e].end() && *it != e ){
          for(int i = 0 ; i <sz(sumiu) ; i++ ){
            if(sumiu[i] == *it){
              swap(sumiu[i], sumiu.back()) ;
              swap(grafos[i] , grafos.back()) ;
              swap(melou[i] , melou.back()) ;
              melou.pop_back() ;
              sumiu.pop_back() ;
              grafos.pop_back() ;
            }
          }
          it = s.erase(it) ;
        }
        else it++ ;
      }
    }
  }

  for(int i = 0 ; i < sz(sumiu) ; i++ ){
      if(A == sumiu[i] || B == sumiu[i] ) continue ;
      grafos[i][A]++ ;
      grafos[i][B]++ ;
      join(i,A,B) ;
      if(grafos[i][A] > 2 || grafos[i][B] > 2 ) melou[i] = true ;
    }


}

int CountCritical() {

  if(sumiu.empty() ) return N ;

  int ans = 0 ;
  for(int i = 0 ; i < sz(melou) ; i++ )
    if(!melou[i]) ans++ ;

  return ans ;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 13 ms 24020 KB Output is correct
3 Correct 14 ms 23964 KB Output is correct
4 Incorrect 13 ms 23764 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 293 ms 40032 KB Output is correct
2 Correct 542 ms 64064 KB Output is correct
3 Correct 380 ms 71904 KB Output is correct
4 Incorrect 721 ms 68480 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 13 ms 24020 KB Output is correct
3 Correct 14 ms 23964 KB Output is correct
4 Incorrect 13 ms 23764 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 13 ms 24020 KB Output is correct
3 Correct 14 ms 23964 KB Output is correct
4 Incorrect 13 ms 23764 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 13 ms 24020 KB Output is correct
3 Correct 14 ms 23964 KB Output is correct
4 Incorrect 13 ms 23764 KB Output isn't correct
5 Halted 0 ms 0 KB -