Submission #1368006

#TimeUsernameProblemLanguageResultExecution timeMemory
1368006mannshah1211Thousands 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 {
 public:
  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 += 2) {
    g[u[i]].push_back(v[i]);
    g[v[i]].push_back(u[i]);
  }
  vector<bool> vis(n);
  auto Dfs = [&](auto&& self, int v) -> void {
    vis[v] = true;
    for (int u : g[v]) {
      if (!vis[u]) {
        self(self, u);
      }
    }
  };
  Dfs(Dfs, 0);
  bool cyc = false;
  for (int i = 0; i < m; i += 2) {
    if (vis[u[i]] && vis[v[i]]) {
      if (!ds.unite(u[i], v[i])) {
        cyc = true;
      }
    }
  }
  if (cyc) {
    return true;
  }
  return false;
}

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:55:12: error: 'ds' was not declared in this scope; did you mean 'dsu'?
   55 |       if (!ds.unite(u[i], v[i])) {
      |            ^~
      |            dsu