Submission #948098

#TimeUsernameProblemLanguageResultExecution timeMemory
948098Nhoksocqt1Thousands Islands (IOI22_islands)C++17
Compilation error
0 ms0 KiB
#ifndef Nhoksocqt1 #include "islands.h" #endif // Nhoksocqt1 #include<bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f #define sz(x) int((x).size()) #define fi first #define se second typedef long long ll; typedef pair<int, int> ii; template<class X, class Y> inline bool maximize(X &x, const Y &y) {return (x < y ? x = y, 1 : 0);} template<class X, class Y> inline bool minimize(X &x, const Y &y) {return (x > y ? x = y, 1 : 0);} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int Random(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); } const int MAXN = 100005; vector<ii> adj[MAXN]; map<ii, int> cntEdge; ii edge[2 * MAXN]; int numNode, numEdge; int getCntEdge(ii p) { return (cntEdge.find(p) != cntEdge.end()) ? cntEdge[p] : 0; } #ifdef Nhoksocqt1 vector<int> #else variant<bool, vector<int>> #endif // Nhoksocqt1 find_journey(int _N, int _M, vector<int> _U, vector<int> _V) { numNode = _N, numEdge = _M; for (int i = 0; i < numEdge; ++i) { int u(_U[i]), v(_V[i]); edge[i] = {u, v}; adj[u].push_back(ii(v, i)); adj[v].push_back(ii(u, i)); ++cntEdge[ii(u, v)]; } int x(-1), y(-1); for (int i = 1; i < numNode; ++i) { if(getCntEdge(ii(0, i)) > 1 && getCntEdge(ii(i, 0)) > 0) { x = i; break; } } if(x != -1) { int cnt0(0), cnt1(0); for (int i = 0; i < numEdge; ++i) { cnt0 += (edge[i].fi == 0); cnt1 += (edge[i].fi == x); } int id0_1(-1), id0_2(-1), idx(-1); for (int i = 0; i < numEdge; ++i) { if(edge[i].fi == 0) { if(id0_1 < 0) { id0_1 = i; } else { id0_2 = i; } } else { idx = i; } } return {id0_1, idx, id0_2, id0_1, idx, id0_2}; } for (int i = 1; i < numNode; ++i) { if(getCntEdge(ii(0, i)) > 0 && getCntEdge(ii(i, 0)) > 0) { if(x < 0) { x = i; } else { y = i; } } } if(y >= 0) { int id0_x(-1), idx_0(-1), id0_y(-1), idy_0(-1); for (int i = 0; i < numEdge; ++i) { int u(edge[i].fi), v(edge[i].se); if(u == 0 && v == x) id0_x = i; if(u == x && v == 0) idx_0 = i; if(u == 0 && v == y) id0_y = i; if(u == y && v == 0) idy_0 = i; } return {id0_x, idx_0, id0_y, idy_0, idx_0, id0_x, idy_0, id0_y}; } x = y = -1; #ifdef Nhoksocqt1 return {-1}; #else return false; #endif // Nhoksocqt1 } #ifdef Nhoksocqt1 int main(void) { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define TASK "islands" if(fopen(TASK".inp", "r")) { freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout); } vector<int> _U, _V; int _N, _M; cin >> _N >> _M; _U.resize(_M), _V.resize(_M); for (int i = 0; i < _M; ++i) cin >> _U[i] >> _V[i]; vector<int> p = find_journey(_N, _M, _U, _V); cout << "ANSWER: "; if(sz(p) == 1 && p[0] == -1) { cout << "NO\n"; } else { for (int it = 0; it < sz(p); ++it) cout << p[it] << ' '; cout << '\n'; } return 0; } #endif // Nhoksocqt1

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:78:53: error: could not convert '{id0_1, idx, id0_2, id0_1, idx, id0_2}' from '<brace-enclosed initializer list>' to 'std::variant<bool, std::vector<int, std::allocator<int> > >'
   78 |         return {id0_1, idx, id0_2, id0_1, idx, id0_2};
      |                                                     ^
      |                                                     |
      |                                                     <brace-enclosed initializer list>
islands.cpp:108:71: error: could not convert '{id0_x, idx_0, id0_y, idy_0, idx_0, id0_x, idy_0, id0_y}' from '<brace-enclosed initializer list>' to 'std::variant<bool, std::vector<int, std::allocator<int> > >'
  108 |         return {id0_x, idx_0, id0_y, idy_0, idx_0, id0_x, idy_0, id0_y};
      |                                                                       ^
      |                                                                       |
      |                                                                       <brace-enclosed initializer list>