Submission #635743

#TimeUsernameProblemLanguageResultExecution timeMemory
635743null_aweStranded Far From Home (BOI22_island)C++14
Compilation error
0 ms0 KiB
#include <iostream> #include <vector> #include <algorithm> #include <set> #include <queue> using namespace std; #define ll long long #define pii pair<int, int> const int INF = 1e9; vector<int> r, p; int find(int a) { return a == p[a] ? a : p[a] = find(p[a]); } void link(int a, int b) { a = find(a), b = find(b); if (a == b) return; if (r[a] < r[b]) swap(a, b); if (r[a] == r[b]) ++r[a]; p[b] = a; } int main() { int n, m; cin >> n >> m; vector<int> nodes(n); for (int i = 0; i < n; ++i) cin >> nodes[i]; vector<pii> arr(n); for (int i = 0; i < n; ++i) arr[i] = {nodes[i], i}; sort(arr.begin(), arr.end()), reverse(arr.begin(), arr.end()); vector<int> io(n); for (int i = 0; i < n; ++i) io[arr[i].second] = i; vector<vector<int>> adj(n); for (int i = 0; i < m; ++i) { int a, b; cin >> a >> b; --a, --b; adj[a].push_back(b), adj[b].push_back(a); } r.resize(n), p.resize(n); for (int i = 0; i < n; ++i) p[i] = i; vector<ll> sizes(n), psizes(n); for (int i = n - 1; i >= 0; --i) { int v = arr[i].second; sizes[v] = nodes[v]; bool bs = false; set<int> done; for (int u : adj[v]) { if (io[u] < io[v] && nodes[u] == nodes[v]) bs = true; if (io[u] < io[v] || done.count(find(u))) continue; sizes[v] += psizes[find(u)], done.insert(find(u)); } if (!bs) for (int u : adj[v]) if (nodes[u] == nodes[v]) sizes[u] = sizes[v]; for (int u : adj[v]) if (io[u] > io[v]) link(u, v); psizes[find(v)] = sizes[v]; } vector<int> nd(n, INF); nd[arr[0].second] = 0; for (int i = 1; i < n; ++i) { for (int u : adj[arr[i].second]) { if (io[u] > i || nd[u] == INF || nodes[u] > sizes[arr[i]].second) continue; nd[arr[i]].second = 0; } } /* queue<pii> q; q.push({arr[0].second, -1}); while (q.size()) { int v = q.front().first, from = q.front().second, rn = max(nodes[v], nd[v]); q.pop(); cout << v << ' ' << nd[v] << '\n'; for (int u : adj[v]) { if (u == from) continue; ll need; if (nodes[u] >= nodes[v]) need = max(nd[v] - sizes[u] + sizes[v], 0LL); else need = max(max(nodes[v] - sizes[u], (ll) nd[v]), 0LL); if (need < nd[u]) { nd[u] = need; q.push({u, v}); } } } */ //for (int num : nd) cout << num << '\n'; for (int i = 0; i < n; ++i) cout << (nd[i] == 0); cout << '\n'; //for (ll sz : sizes) cout << sz << ' '; //cout << '\n'; return 0; }

Compilation message (stderr)

island.cpp: In function 'int main()':
island.cpp:55:56: error: no match for 'operator[]' (operand types are 'std::vector<long long int>' and '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'})
   55 |       if (io[u] > i || nd[u] == INF || nodes[u] > sizes[arr[i]].second) continue;
      |                                                        ^
In file included from /usr/include/c++/10/vector:67,
                 from island.cpp:2:
/usr/include/c++/10/bits/stl_vector.h:1043:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = long long int; _Alloc = std::allocator<long long int>; std::vector<_Tp, _Alloc>::reference = long long int&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1043:28: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} to 'std::vector<long long int>::size_type' {aka 'long unsigned int'}
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1061:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) const [with _Tp = long long int; _Alloc = std::allocator<long long int>; std::vector<_Tp, _Alloc>::const_reference = const long long int&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1061:28: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} to 'std::vector<long long int>::size_type' {aka 'long unsigned int'}
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
island.cpp:56:9: error: no match for 'operator[]' (operand types are 'std::vector<int>' and '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'})
   56 |       nd[arr[i]].second = 0;
      |         ^
In file included from /usr/include/c++/10/vector:67,
                 from island.cpp:2:
/usr/include/c++/10/bits/stl_vector.h:1043:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::reference = int&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1043:28: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} to 'std::vector<int>::size_type' {aka 'long unsigned int'}
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1061:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) const [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::const_reference = const int&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1061:28: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} to 'std::vector<int>::size_type' {aka 'long unsigned int'}
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~