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 <variant>
#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int,int>>> adj;
vector<int> path,cycle;
vector<bool> used;
void dfs(int v, int e) {
used[v] = true;
if (adj[v].size() > 2) {
int p1,p2;
if (adj[v][0].first == e) {
p1 = adj[v][1].second;
p2 = adj[v][2].second;
}else if (adj[v][1].first == e) {
p1 = adj[v][0].second;
p2 = adj[v][2].second;
}else {
p1 = adj[v][0].second;
p2 = adj[v][1].second;
}
int b1=p1^1,b2=p2^1;
cycle = {p1,b1,p2,b2,b1,p1,b2,p2};
return;
}
for (auto u: adj[v]) {
if (!used[u.first]) {
path.push_back(u.second);
dfs(u.first,v);
}
}
}
variant<bool,vector<int>> find_journey( int n, int m, vector<int> u, vector<int> v) {
adj.resize(n); used.resize(n);
for (int i=0;i<m;i++) {
adj[u[i]].push_back({v[i],i});
}
if (adj[0].size() > 1) {
int p1 = adj[0][0].second; int b1 = p1^1;
int p2 = adj[0][1].second; int b2 = p2^1;
vector<int> ans = {p1,b1,p2,b2,b1,p1,b2,p1};
return ans;
} else {
dfs(0,-1);
if (cycle.size() == 0) {
return false;
}
vector<int> ans;
ans.insert(ans.end(),path.begin(),path.end());
ans.insert(ans.end(),cycle.begin(),cycle.end());
reverse(path.begin(),path.end());
ans.insert(ans.end(),path.begin(),path.end());
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... |