Submission #786449

#TimeUsernameProblemLanguageResultExecution timeMemory
786449khshgThousands Islands (IOI22_islands)C++17
Compilation error
0 ms0 KiB
#include "islands.h" #include<bits/stdc++.h> using namespace std; vector<vector<pair<int, int>>> adj; vector<int> c; bool dfs(int s, vector<int>& nds) { nds.push_back(s); c[s] = 1; for(auto& u : adj[s]) { if(c[u] == 0) if(dfs(u, nds)) return 1; else if(c[u] == 1) { nds.push_back(u); return 1; } } nds.pop_back(); nds[s] = 2; return false; } variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) { //vector<int> find_journey(int N, int M, vector<int> U, vector<int> V) { c.resize(N); adj.resize(N); for(int i = 0; i < M; i += 2) { adj[U[i]].emplace_back(V[i], i); } vector<int> ans; vector<int> nds; return dfs(0, nds); /* int cur = 0, prev = -1; vector<int> way, ans; while(1) { int cs = out[cur] - (prev != -1); if(cs == 0) return false; if(cs == 1) { for(auto& u : adj[cur]) if(u.first != prev) { way.push_back(u.second[0]); prev = cur; cur = u.first; break; } continue; } break; } //return true; ans = way; vector<pair<int, int>> z; for(auto& u : adj[cur]) if(u.first != prev) { for(auto& v : u.second) { z.push_back(v); if((int)z.size() == 2) break; } if((int)z.size() == 2) break; } ans.push_back(z[0]); ans.push_back(z[0] / 2 * 4 + 1 - z[0]); ans.push_back(z[1]); ans.push_back(z[1] / 2 * 4 + 1 - z[1]); ans.push_back(z[0] / 2 * 4 + 1 - z[0]); ans.push_back(z[0]); ans.push_back(z[1] / 2 * 4 + 1 - z[1]); ans.push_back(z[1]); reverse(begin(way), end(way)); for(auto& u : way) ans.push_back(u); return ans;*/ } /* int main() { int N, M; assert(2 == scanf("%d %d", &N, &M)); std::vector<int> U(M), V(M); for (int i = 0; i < M; ++i) { assert(2 == scanf("%d %d", &U[i], &V[i])); } vector<int> result = find_journey(N, M, U, V); for(auto& u : result) { cout << u << '\n'; } }*/

Compilation message (stderr)

islands.cpp: In function 'bool dfs(int, std::vector<int>&)':
islands.cpp:11:7: error: no match for 'operator[]' (operand types are 'std::vector<int>' and 'std::pair<int, int>')
   11 |   if(c[u] == 0) if(dfs(u, nds)) return 1;
      |       ^
In file included from /usr/include/c++/10/vector:67,
                 from islands.h:2,
                 from islands.cpp:1:
/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 '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 'std::pair<int, int>' to 'std::vector<int>::size_type' {aka 'long unsigned int'}
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
islands.cpp:11:24: error: cannot convert 'std::pair<int, int>' to 'int'
   11 |   if(c[u] == 0) if(dfs(u, nds)) return 1;
      |                        ^
      |                        |
      |                        std::pair<int, int>
islands.cpp:7:14: note:   initializing argument 1 of 'bool dfs(int, std::vector<int>&)'
    7 | bool dfs(int s, vector<int>& nds) {
      |          ~~~~^
islands.cpp:12:12: error: no match for 'operator[]' (operand types are 'std::vector<int>' and 'std::pair<int, int>')
   12 |   else if(c[u] == 1) {
      |            ^
In file included from /usr/include/c++/10/vector:67,
                 from islands.h:2,
                 from islands.cpp:1:
/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 '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 'std::pair<int, int>' to 'std::vector<int>::size_type' {aka 'long unsigned int'}
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
islands.cpp:13:19: error: no matching function for call to 'std::vector<int>::push_back(std::pair<int, int>&)'
   13 |    nds.push_back(u);
      |                   ^
In file included from /usr/include/c++/10/vector:67,
                 from islands.h:2,
                 from islands.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from 'std::pair<int, int>' to 'const value_type&' {aka 'const int&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from 'std::pair<int, int>' to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
islands.cpp:11:5: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   11 |   if(c[u] == 0) if(dfs(u, nds)) return 1;
      |     ^