This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "islands.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
vector<int> vis, at;
vector<vector<pii>> edges;
pii dfs(int x, int pai) {
vis[x] = 1;
if(pai != -1) at.pb(pai);
vector<int> e;
for(auto [viz,ind] : edges[x]) if(ind/2 != pai/2) e.pb(ind);
if(sz(e) >= 2) return {e[0], e[1]};
for(auto [viz,ind] : edges[x]){
if(vis[viz]) continue;
pii a = dfs(viz, ind);
if(a.fr != -1) return a;
}
at.pop_back();
return {-1,-1};
}
variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) {
edges.resize(N);
vis.resize(N);
for(int i = 0; i < M; i++) edges[U[i]].pb({V[i], i});
auto [a,b] = dfs(0, -1);
if(a == -1) return false;
vector<int> ans;
for(int i = 0; i < sz(at); i++) ans.pb(at[i]);
int c = a + 1 - 2*(a%2), d = b + 1 - 2*(b%2);
ans.pb(a);
ans.pb(c);
ans.pb(b);
ans.pb(d);
ans.pb(c);
ans.pb(a);
ans.pb(d);
ans.pb(b);
for(int i = sz(at) - 1; i >= 0; i--) ans.pb(at[i]);
return ans;
}
# | 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... |