Submission #837952

# Submission time Handle Problem Language Result Execution time Memory
837952 2023-08-25T21:21:18 Z taher Rarest Insects (IOI22_insects) C++17
0 / 100
1 ms 260 KB
#include "insects.h"
#include <bits/stdc++.h>

using namespace std;

class dsu {
  public:
  int n;
  vector<int> par;
  vector<int> size;
  
  dsu(int _n) : n(_n) {
    par.resize(n);
    iota(par.begin(), par.end(), 0);
    size.resize(n);
    for (int i = 0; i < n; i++) {
      size[i] = 1; 
    }
  }
  
  int get(int x) {
    if (par[x] == x) {
      return par[x];
    }
    return par[x] = get(par[x]); 
  }
  
  bool unite(int x, int y) {
    x = get(x);
    y = get(y);
    
    if (x == y) {
      return false; 
    }
    par[x] = y;
    size[y] += size[x];
    return true; 
  }
};

int min_cardinality(int N) {

  int n = N;
  
  dsu ds(n);

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      move_inside(i);
      move_inside(j);
      
      if (press_button() == 1) {
        ds.unite(i, j); 
      }
    }
  }
  
  int res = 123456;
  
  for (int i = 0; i < n; i++) {
    if (ds.get(i) == i) {
      res = min(res, ds.size[i]); 
    }
  }
  return res;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB Wrong answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB Wrong answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 260 KB Output is correct
2 Incorrect 0 ms 208 KB Wrong answer.
3 Halted 0 ms 0 KB -