#include "islands.h"
#include<bits/stdc++.h>
using namespace std;
variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V){
vector<vector<pair<int,int>>> g(N);
for (int i=0; i<M; i+=2){
g[U[i]].push_back({V[i], i});
g[V[i]].push_back({U[i], i+1});
}
vector<int> p1, p2;
int cur = 0, prev = 0;
while (true){
vector<pair<int,int>> next;
for (pair<int,int> neigh : g[cur]){
if (neigh.first != prev) next.push_back(neigh);
}
if (next.size() == 0) return false;
if (next.size() == 1){
p1.push_back(next[0].second);
prev = cur;
cur = next[0].first;
}
if (next.size() >= 2){
p2.push_back(next[0].second);
p2.push_back(next[0].second ^ 1);
p2.push_back(next[1].second);
p2.push_back(next[1].second ^ 1);
p2.push_back(next[0].second ^ 1);
p2.push_back(next[0].second);
p2.push_back(next[1].second ^ 1);
p2.push_back(next[1].second);
break;
}
}
vector<int> res;
for (int x : p1) res.push_back(x);
for (int x : p2) res.push_back(x);
reverse(p1.begin(), p1.end());
for (int x : p1) res.push_back(x);
return res;
}
# | 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... |