#include "islands.h"
#include <map>
#include <variant>
#include <vector>
using namespace std;
#define pb push_back
#define mp make_pair
variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) {
	// subtask 1,2 accomplished
	// subtask 3 (21 marks)
	vector<vector<int>> adj(N);
	map<pair<int, int>, int> can;
	int u,v;
	for(int i=0; i<M; i++){
		u=U[i];
		v=V[i];
		adj[u].pb(v);
		can[mp(u,v)]=i;
	}
	vector<int> answer;
	if(adj[0].size() > 1){
		// simple case (same as subtask 2)
		answer = {can[mp(0, adj[0][0])], can[mp(adj[0][0], 0)], 
			can[mp(0, adj[0][1])], can[mp(adj[0][1], 0)], 
			can[mp(adj[0][0], 0)], can[mp(0, adj[0][0])], 
			can[mp(adj[0][1], 0)], can[mp(0, adj[0][1])]};
		return answer;
	}
	if(adj[0].size() == 0)return false;
	// complex case
	int cur = adj[0][0];
	int prev = 0;
	vector<int> beforetrip={ can[mp(prev, cur)] };
	vector<int> aftertrip= { can[mp(cur, prev)] };
	while(true){
		if(adj[cur].size()==1){
			return false;
		} else if(adj[cur].size()==2){
			if(adj[cur][0]==prev){
				prev = cur;
				cur = adj[cur][1];
			} else{
				prev = cur;
				cur = adj[cur][0];
			}
		} else{
			// we have the trip!
			return true;
		}
	}
		
	return false;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |