Submission #1187766

#TimeUsernameProblemLanguageResultExecution timeMemory
1187766ByeWorldThousands Islands (IOI22_islands)C++20
Compilation error
0 ms0 KiB
#include "islands.h"
#include <bits/stdc++.h>
#include <variant>
#include <vector>
#define ll long long
#define pb push_back
#define fi first
#define se second
#define lf ((id<<1))
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
using namespace std;
const int MAXN = 2e5+10;
typedef pair<int,int> pii;

int n, m;
int u[MAXN], v[MAXN];
vector<int> ANS;
vector<pii> adj[MAXN];
bool vis[MAXN];
vector<int> stac, cyc;
map<pii,int> ma, ma2;
vector<int> go;
bool ada = 0;

void dfs(int nw, int pa){
	if(adj[nw].size() >= 3) ada = 1;
	vis[nw] = 1;
	stac.pb(nw);
	for(auto [nx, ed] : adj[nw]){
		if(abs(ed-pa)==1 && u[ed]==v[pa] && u[pa]==v[ed]) continue;
		if(!cyc.empty()) return;

		if(vis[nx]){
			while(stac.back() != nx){
				cyc.pb(stac.back()); stac.pop_back();
			}
			cyc.pb(nx);

			int ba = stac.back(); stac.pop_back();
			while(!stac.empty()){
				go.pb(ma[pii(stac.back(), ba)]);
				ba = stac.back(); stac.pop_back();
			}
			return;
 		} else dfs(nx, ed);
	}
}

std::variant<bool, std::vector<int>> find_journey(
    int N, int M, std::vector<int> U, std::vector<int> V) {
	n = N; m = M;
	for(int i=0; i<m; i++){
		u[i] = U[i]+1, v[i] = V[i]+1;
		ma[pii(u[i], v[i])] = i; 
		adj[u[i]].pb({v[i], i});
	}
	dfs(1, -1);

	// for(auto in : cyc){
	// 	cout << in << " in\n";
	// }
	if(!cyc.empty()){
		reverse(cyc.begin(), cyc.end());
		for(int i=go.size()-1; i>=0; i--) ANS.pb(go[i]);
		cyc.pb(cyc[0]);

		if(cyc.size() == 3){

			for(int i=0; i<m; i++){
				if(ma[pii(u[i], v[i])] == i) continue;
				ma2[pii(u[i], v[i])] = i;
			}
			for(int i=0; i+1<cyc.size(); i++){ // ac
				int nx = cyc[i+1];
				ANS.pb(ma[pii(cyc[i], nx)]);
			}
			for(int i=cyc.size()-1; i>=1; i--){ // fd
				int nx = cyc[i-1];
				ANS.pb(ma2[pii(cyc[i], nx)]);
			}
			for(int i=cyc.size()-1; i>=1; i--){ // fd
				int nx = cyc[i-1];
				ANS.pb(ma[pii(nx, cyc[i])]);
			}
			for(int i=0; i+1<cyc.size(); i++){ // ac
				int nx = cyc[i+1];
				ANS.pb(ma2[pii(nx, cyc[i])]);
			}
		} else {
			for(int i=0; i+1<cyc.size(); i++){ // ac
				int nx = cyc[i+1];
				ANS.pb(ma[pii(cyc[i], nx)]);
			}
			for(int i=cyc.size()-1; i>=1; i--){ // fd
				int nx = cyc[i-1];
				ANS.pb(ma[pii(cyc[i], nx)]);
			}
			for(int i=cyc.size()-1; i>=1; i--){ // fd
				int nx = cyc[i-1];
				ANS.pb(ma[pii(nx, cyc[i])]);
			}
			for(int i=0; i+1<cyc.size(); i++){ // ac
				int nx = cyc[i+1];
				ANS.pb(ma[pii(nx, cyc[i])]);
			}
		}

		for(int i=0; i<go.size(); i++) ANS.pb(go[i]);
		return ANS;
	}
	if(adj[1].size() >= 2) ada = 1;
	if(ada) return {1};
	return false;
}

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:113:26: error: could not convert '{1}' from '<brace-enclosed initializer list>' to 'std::variant<bool, std::vector<int, std::allocator<int> > >'
  113 |         if(ada) return {1};
      |                          ^
      |                          |
      |                          <brace-enclosed initializer list>