Submission #598760

#TimeUsernameProblemLanguageResultExecution timeMemory
598760BobaaKeys (IOI21_keys)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10; int par[maxn], sz[maxn], bad[maxn], state[maxn], lst[maxn]; map<int, vector<int>> g[maxn]; set<int> key[maxn]; vector<int> to[maxn]; namespace dsu { int Find(int u) { return (u == par[u] ? u : par[u] = find(par[u])); } void Union(int u, int v) { if ((u = Find(u)) == (v = Find(v))) return; if (sz[u] < sz[v]) swap(u, v); par[v] = u; sz[u] += sz[v]; if (key[u].size() + to[u].size() < key[v].size() + to[v].size()) { swap(key[u], key[v]); swap(to[u], to[v]); } for (auto w : to[v]) to[u].push_back(w); to[v].clear(); for (auto c : key[v]) if (g[u].find(c) != g[u].end()) { for (auto w : g[u][c]) to[u].push_back(w); g[u].erase(c); } for (auto [c, _] : g[v]) { if (g[u].find(c) != g[u].end()) for (auto w : g[v][c]) to[u].push_back(w); else for (auto w : g[v][c]) g[u][c].push_back(w); } g[v].clear(); key[u].insert(key[v].begin(), key[v].end()); key[v].clear(); } } using namespace dsu; void dfs(int u) { state[u] = 0; while (1) { u = Find(u); if (to[u].empty()) break; int v = to[u].back(); to[u].pop_back(); v = Find(v); if (u == v) continue; if (state[v] == -1) { lst[v] = u; dfs(v); if (Find(u) != Find(v)) bad[u] = 1; } else if (state[v] == 0) { int w = u; while (1) { if (Find(w) == Find(v)) break; Union(w, v); w = lst[w]; } } else bad[u] = 1; } state[u] = 1; } vector<int> find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c) { int n = r.size(), m = c.size(); auto adde = [&](int u, int v, int c) { if (r[u] == c) to[u].push_back(v); else g[u][c].push_back(v); }; for (int i = 0; i < m; i++) { adde(u[i], v[i], c[i]); adde(v[i], u[i], c[i]); } for (int i = 0; i < n; i++) { par[i] = i; sz[i] = 1; key[i].insert(r[i]); } memset(state, -1, sizeof(state)); for (int i = 0; i < n; i++) if (state[i] == -1) dfs(i); for (int i = 0; i < n; i++) if (bad[i]) bad[Find(i)] = 1; vector<int> flg(n, 0); int ans = 1e9; for (int i = 0; i < n; i++) if (i == Find(i) && !bad[i]) ans = min(ans, sz[i]); for (int i = 0; i < n; i++) if (!bad[Find(i)] && sz[Find(i)] == ans) flg[i] = 1; return flg; }

Compilation message (stderr)

keys.cpp: In function 'int dsu::Find(int)':
keys.cpp:13:49: error: no matching function for call to 'find(int&)'
   13 |   return (u == par[u] ? u : par[u] = find(par[u]));
      |                                                 ^
In file included from /usr/include/c++/10/bits/locale_facets.h:48,
                 from /usr/include/c++/10/bits/basic_ios.h:37,
                 from /usr/include/c++/10/ios:44,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from keys.cpp:1:
/usr/include/c++/10/bits/streambuf_iterator.h:422:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT> >::__type std::find(std::istreambuf_iterator<_CharT>, std::istreambuf_iterator<_CharT>, const _CharT2&)'
  422 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/10/bits/streambuf_iterator.h:422:5: note:   template argument deduction/substitution failed:
keys.cpp:13:49: note:   mismatched types 'std::istreambuf_iterator<_CharT>' and 'int'
   13 |   return (u == par[u] ? u : par[u] = find(par[u]));
      |                                                 ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from keys.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3894:5: note: candidate: 'template<class _IIter, class _Tp> _IIter std::find(_IIter, _IIter, const _Tp&)'
 3894 |     find(_InputIterator __first, _InputIterator __last,
      |     ^~~~
/usr/include/c++/10/bits/stl_algo.h:3894:5: note:   template argument deduction/substitution failed:
keys.cpp:13:49: note:   candidate expects 3 arguments, 1 provided
   13 |   return (u == par[u] ? u : par[u] = find(par[u]));
      |                                                 ^
In file included from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from keys.cpp:1:
/usr/include/c++/10/pstl/glue_algorithm_defs.h:60:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::find(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
   60 | find(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~
/usr/include/c++/10/pstl/glue_algorithm_defs.h:60:1: note:   template argument deduction/substitution failed:
keys.cpp:13:49: note:   candidate expects 4 arguments, 1 provided
   13 |   return (u == par[u] ? u : par[u] = find(par[u]));
      |                                                 ^