Submission #695049

# Submission time Handle Problem Language Result Execution time Memory
695049 2023-02-04T17:10:57 Z finn__ Stranded Far From Home (BOI22_island) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

struct DSU
{
    vector<int64_t> parent, weight;
    vector<bool> is_bad;

    DSU(size_t n, vector<int64_t> const &s)
    {
        parent = vector<int64_t>(n, -1);
        weight = vector<int64_t>(s.begin(), s.end());
        is_bad = vector<bool>(n, 0);
    }

    int root(int u)
    {
        if (parent[u] < 0)
            return u;
        is_bad[u] |= is_bad[parent[u]];
        return parent[u] = root(parent[u]);
    }

    void merge(int u, int v)
    {
        u = root(u), v = root(v);
        if (u == v)
            return;

        if (parent[u] < parent[v])
            swap(u, v);
        weight[v] += weight[u];
        parent[v] += parent[u];
        parent[u] = v;
    }

    void mark_bad(int u) { is_bad[root(u)] = 1; }

    int64_t component_weight(int u) { return weight[root(u)]; }

    bool get_bad(int u)
    {
        root(u);
        return is_bad[u];
    }
};

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    vector<int64_t> s(n);
    for (int64_t &x : s)
        cin >> x;

    vector<pair<int64_t, unsigned>> nodes(n);
    for (size_t i = 0; i < n; i++)
        nodes[i] = {s[i], i};
    sort(nodes.begin(), nodes.end());

    vector<vector<unsigned>> g(n);
    for (size_t i = 0; i < m; i++)
    {
        unsigned u, v;
        cin >> u >> v;
        g[u - 1].push_back(v - 1);
        g[v - 1].push_back(u - 1);
    }

    DSU dsu(n, s);

    for (auto const &[x, u] : nodes)
    {
        for (unsigned const &v : g[u])
        {
            if (s[v] <= x)
            {
                if (dsu.component_weight(v) < x)
                    dsu.mark_bad(v);
                dsu.merge(u, v);
            }
        }
    }

    for (size_t i = 0; < n; i++)
        cout << (unsigned)!get_bad(i);
    cout << '\n';
}

Compilation message

island.cpp: In member function 'int DSU::root(int)':
island.cpp:20:19: error: no match for 'operator|=' (operand types are 'std::vector<bool>::reference' and 'std::vector<bool>::reference')
   20 |         is_bad[u] |= is_bad[parent[u]];
      |         ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:45,
                 from island.cpp:1:
/usr/include/c++/10/cstddef:160:3: note: candidate: 'constexpr std::byte& std::operator|=(std::byte&, std::byte)'
  160 |   operator|=(byte& __l, byte __r) noexcept
      |   ^~~~~~~~
/usr/include/c++/10/cstddef:160:20: note:   no known conversion for argument 1 from 'std::vector<bool>::reference' to 'std::byte&'
  160 |   operator|=(byte& __l, byte __r) noexcept
      |              ~~~~~~^~~
In file included from /usr/include/c++/10/ios:42,
                 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 island.cpp:1:
/usr/include/c++/10/bits/ios_base.h:99:3: note: candidate: 'const std::_Ios_Fmtflags& std::operator|=(std::_Ios_Fmtflags&, std::_Ios_Fmtflags)'
   99 |   operator|=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b)
      |   ^~~~~~~~
/usr/include/c++/10/bits/ios_base.h:99:29: note:   no known conversion for argument 1 from 'std::vector<bool>::reference' to 'std::_Ios_Fmtflags&'
   99 |   operator|=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b)
      |              ~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/ios_base.h:141:3: note: candidate: 'const std::_Ios_Openmode& std::operator|=(std::_Ios_Openmode&, std::_Ios_Openmode)'
  141 |   operator|=(_Ios_Openmode& __a, _Ios_Openmode __b)
      |   ^~~~~~~~
/usr/include/c++/10/bits/ios_base.h:141:29: note:   no known conversion for argument 1 from 'std::vector<bool>::reference' to 'std::_Ios_Openmode&'
  141 |   operator|=(_Ios_Openmode& __a, _Ios_Openmode __b)
      |              ~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/ios_base.h:181:3: note: candidate: 'const std::_Ios_Iostate& std::operator|=(std::_Ios_Iostate&, std::_Ios_Iostate)'
  181 |   operator|=(_Ios_Iostate& __a, _Ios_Iostate __b)
      |   ^~~~~~~~
/usr/include/c++/10/bits/ios_base.h:181:28: note:   no known conversion for argument 1 from 'std::vector<bool>::reference' to 'std::_Ios_Iostate&'
  181 |   operator|=(_Ios_Iostate& __a, _Ios_Iostate __b)
      |              ~~~~~~~~~~~~~~^~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:105,
                 from island.cpp:1:
/usr/include/c++/10/future:167:18: note: candidate: 'std::launch& std::operator|=(std::launch&, std::launch)'
  167 |   inline launch& operator|=(launch& __x, launch __y)
      |                  ^~~~~~~~
/usr/include/c++/10/future:167:37: note:   no known conversion for argument 1 from 'std::vector<bool>::reference' to 'std::launch&'
  167 |   inline launch& operator|=(launch& __x, launch __y)
      |                             ~~~~~~~~^~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:127,
                 from island.cpp:1:
/usr/include/c++/10/charconv:680:3: note: candidate: 'constexpr std::chars_format& std::operator|=(std::chars_format&, std::chars_format)'
  680 |   operator|=(chars_format& __lhs, chars_format __rhs) noexcept
      |   ^~~~~~~~
/usr/include/c++/10/charconv:680:28: note:   no known conversion for argument 1 from 'std::vector<bool>::reference' to 'std::chars_format&'
  680 |   operator|=(chars_format& __lhs, chars_format __rhs) noexcept
      |              ~~~~~~~~~~~~~~^~~~~
island.cpp: In function 'int main()':
island.cpp:53:23: error: 'n' was not declared in this scope
   53 |     vector<int64_t> s(n);
      |                       ^
island.cpp:63:28: error: 'm' was not declared in this scope
   63 |     for (size_t i = 0; i < m; i++)
      |                            ^
island.cpp:86:24: error: expected primary-expression before '<' token
   86 |     for (size_t i = 0; < n; i++)
      |                        ^
island.cpp:87:28: error: 'get_bad' was not declared in this scope
   87 |         cout << (unsigned)!get_bad(i);
      |                            ^~~~~~~