Submission #1367887

#TimeUsernameProblemLanguageResultExecution timeMemory
1367887mannshah1211Thousands Islands (IOI22_islands)C++20
Compilation error
0 ms0 KiB
#include "islands.h"
#include <bits/stdc++.h>
#include <variant>
#include <vector>

using namespace std;

class dsu {
  vector<int> p;
  int n;

  dsu(int _n) : n(_n) {
    p.resize(n);
    iota(p.begin(), p.end(), 0);
  }

  int get(int x) {
    if (p[x] == x) {
      return x;
    }
    return (p[x] = get(p[x]));
  }

  bool unite(int x, int y) {
    x = get(x);
    y = get(y);
    if (x != y) {
      p[y] = x;
      return true;
    }
    return false;
  }
};

variant<bool, vector<int>> find_journey(int n, int m, vector<int> u, vector<int> v) {
  vector<vector<int>> g(n);
  for (int i = 0; i < m; i++) {
    g[u[i]].push_back(v[i]);
    g[v[i]].push_back(u[i]);
  }
  dsu ds(n);
  bool cyc = false;
  for (int i = 0; i < m; i++) {
    if (!ds.unite(u[i], v[i])) {
      cyc = true;
    }
  }
  if (!cyc) {
    return false;
  }
  return {};
}

Compilation message (stderr)

islands.cpp: In function 'std::variant<bool, std::vector<int, std::allocator<int> > > find_journey(int, int, std::vector<int>, std::vector<int>)':
islands.cpp:41:11: error: 'dsu::dsu(int)' is private within this context
   41 |   dsu ds(n);
      |           ^
islands.cpp:12:3: note: declared private here
   12 |   dsu(int _n) : n(_n) {
      |   ^~~
islands.cpp:44:18: error: 'bool dsu::unite(int, int)' is private within this context
   44 |     if (!ds.unite(u[i], v[i])) {
      |          ~~~~~~~~^~~~~~~~~~~~
islands.cpp:24:8: note: declared private here
   24 |   bool unite(int x, int y) {
      |        ^~~~~