답안 #535190

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
535190 2022-03-09T15:46:44 Z cig32 낙하산 고리들 (IOI12_rings) C++17
20 / 100
1631 ms 262148 KB
#include "bits/stdc++.h"
using namespace std;
const int MAXN = 1e6 + 10;

int N;

int dsu[MAXN];
int cnt[MAXN]; // count of nodes w degree 1 in such component
int sz[MAXN];
int set_of(int u) {
  if(dsu[u] == u) return u;
  return dsu[u] = set_of(dsu[u]);
}

void union_(int u, int v) {
  dsu[set_of(u)] = set_of(v);
}

void Init(int N_) {

  N = N_;
  for(int i=0; i<N; i++) dsu[i] = i, cnt[i] = 0, sz[i] = 1;

}

vector<int> adj[MAXN];

set<int> deg3, deg4;//deg4: at least 4, deg3: == 3
unordered_map<int, int> owo[MAXN];
int dailo = -1;
bool sad = 0;

set<int> well_fucked;
void Link(int A, int B) {
  
  adj[A].push_back(B);
  adj[B].push_back(A);
  owo[A][B] = owo[B][A] = 1;
  if(set_of(A) != set_of(B)) {
    int old1 = set_of(A);
    int old2 = set_of(B);
    union_(A, B);
    cnt[set_of(A)] = cnt[old1] + cnt[old2] - (adj[A].size() == 2) - (adj[B].size() == 2) + (adj[A].size() == 1) + (adj[B].size() == 1);
    sz[set_of(A)] = sz[old1] + sz[old2];
  }
  else {
    cnt[set_of(A)] = cnt[set_of(A)] - (adj[A].size() == 2) - (adj[B].size() == 2) + (adj[A].size() == 1) + (adj[B].size() == 1);
  }
  if(cnt[set_of(A)] == 0) {
    well_fucked.insert(set_of(A));
  }
  if(cnt[set_of(A)] > 0) {
    well_fucked.erase(set_of(A));
  }
  if(adj[A].size() == 3) {
    deg3.insert(A);
    if(dailo != -1) {
      if(!owo[dailo][A]) {
        sad = 1;
      }
    }
  }
  if(adj[B].size() == 3) {
    deg3.insert(B);
    if(dailo != -1) {
      if(!owo[dailo][B]) {
        sad = 1;
      }
    }
  }
  if(adj[A].size() == 4) {
    deg4.insert(A);
    deg3.erase(A);
    if(dailo == -1) {
      dailo = A;
      for(int x: deg3) {
        if(!owo[A][x]) {
          sad = 1; break;
        }
      }
    }
  }
  if(adj[B].size() == 4) {
    deg4.insert(B);
    deg3.erase(B);
    if(dailo == -1) {
      dailo = B;
      for(int x: deg3) {
        if(!owo[B][x]) {
          sad = 1; break;
        }
      }
    }
  }
}

int CountCritical() {
  if(deg4.size() > 1) return 0;
  if(deg4.size() == 1 && sad) return 0;
  else if(deg4.size() == 1) return 1;
  // deg4.size = 0
  if(deg3.size() > 4) return 0;
  if(deg3.size() <= 4 && deg3.size() >= 1) {
    set<int> ans;
    for(int x: deg3) {
      bool rip = 0;
      for(int y: deg3) {
        if(x != y && !owo[x][y]) rip = 1;
      }
      if(!rip) {
        ans.insert(x);
      }
    }
    for(int x: deg3) {
      for(int i=0; i<adj[x].size(); i++) {
        int uwu = 0;
        for(int j=0; j<adj[adj[x][i]].size(); j++) {
          uwu += (adj[adj[adj[x][i]][j]].size() == 3);
        }
        if(uwu == deg3.size()) ans.insert(adj[x][i]);
      }
    }
    // everything must be connected, else no solution
    vector<int> fin;
    for(int x: ans) {
      int d = cnt[set_of(x)];
      if(adj[x].size() == 1) d--;
      for(int y: adj[x]) if(adj[y].size() == 1) d--;
      for(int y: adj[x]) if(adj[y].size() == 2) d++;
      if(d > 0) fin.push_back(x);
    }
    return fin.size();
  }
  // deg3.size = deg4.size = 0
  // all nodes shld be (in theory) ok
  if(well_fucked.size() == 1) {
    return sz[set_of(*well_fucked.begin())];
  }
  if(well_fucked.size() > 1) {
    return 0;
  }
  return N;
}

Compilation message

rings.cpp: In function 'int CountCritical()':
rings.cpp:115:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |       for(int i=0; i<adj[x].size(); i++) {
      |                    ~^~~~~~~~~~~~~~
rings.cpp:117:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  117 |         for(int j=0; j<adj[adj[x][i]].size(); j++) {
      |                      ~^~~~~~~~~~~~~~~~~~~~~~
rings.cpp:120:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  120 |         if(uwu == deg3.size()) ans.insert(adj[x][i]);
      |            ~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 78568 KB Output is correct
2 Correct 45 ms 79516 KB Output is correct
3 Correct 43 ms 79652 KB Output is correct
4 Correct 42 ms 78704 KB Output is correct
5 Correct 43 ms 79224 KB Output is correct
6 Correct 45 ms 79684 KB Output is correct
7 Correct 41 ms 78792 KB Output is correct
8 Correct 44 ms 79428 KB Output is correct
9 Correct 44 ms 79684 KB Output is correct
10 Correct 43 ms 79704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 768 ms 197272 KB Output is correct
2 Correct 1487 ms 261024 KB Output is correct
3 Runtime error 1631 ms 262148 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 78568 KB Output is correct
2 Correct 45 ms 79516 KB Output is correct
3 Correct 43 ms 79652 KB Output is correct
4 Correct 42 ms 78704 KB Output is correct
5 Correct 43 ms 79224 KB Output is correct
6 Correct 45 ms 79684 KB Output is correct
7 Correct 41 ms 78792 KB Output is correct
8 Correct 44 ms 79428 KB Output is correct
9 Correct 44 ms 79684 KB Output is correct
10 Correct 43 ms 79704 KB Output is correct
11 Incorrect 47 ms 79684 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 78568 KB Output is correct
2 Correct 45 ms 79516 KB Output is correct
3 Correct 43 ms 79652 KB Output is correct
4 Correct 42 ms 78704 KB Output is correct
5 Correct 43 ms 79224 KB Output is correct
6 Correct 45 ms 79684 KB Output is correct
7 Correct 41 ms 78792 KB Output is correct
8 Correct 44 ms 79428 KB Output is correct
9 Correct 44 ms 79684 KB Output is correct
10 Correct 43 ms 79704 KB Output is correct
11 Incorrect 47 ms 79684 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 78568 KB Output is correct
2 Correct 45 ms 79516 KB Output is correct
3 Correct 43 ms 79652 KB Output is correct
4 Correct 42 ms 78704 KB Output is correct
5 Correct 43 ms 79224 KB Output is correct
6 Correct 45 ms 79684 KB Output is correct
7 Correct 41 ms 78792 KB Output is correct
8 Correct 44 ms 79428 KB Output is correct
9 Correct 44 ms 79684 KB Output is correct
10 Correct 43 ms 79704 KB Output is correct
11 Correct 768 ms 197272 KB Output is correct
12 Correct 1487 ms 261024 KB Output is correct
13 Runtime error 1631 ms 262148 KB Execution killed with signal 9
14 Halted 0 ms 0 KB -