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 <variant>
#include <bits/stdc++.h>
using namespace std;
const int N = 1001;
int deg[N];
bool vis[N];
vector <pair<int, int>> adj[N];
vector <int> path, ok;
map <pair<int, int> , int> mp;
int n;
void dfs(int u){
vis[u] = true;
path.push_back(u);
if (deg[u] >= 3 && ok.size() == 0){
ok = path;
}
for (auto [v, i] : adj[u]){
if (!vis[v]) dfs(v);
}
path.pop_back();
}
void get(vector <int> &ans, int x, int y){
ans.push_back(x);
ans.push_back(x ^ 1);
ans.push_back(y);
ans.push_back(y ^ 1);
ans.push_back(x ^ 1);
ans.push_back(x);
ans.push_back(y ^ 1);
ans.push_back(y);
}
variant<bool, vector<int>> find_journey(int nn, int m, vector<int> u, vector<int> v) {
n = nn;
for (int i = 0; i < m; i++){
adj[u[i]].push_back({v[i], i});
mp[{u[i], v[i]}] = i;
deg[u[i]]++;
}
vector <int> ans;
if (deg[0] >= 2){
int v1 = adj[0][0].second;
int v2 = adj[0][1].second;
get(ans, v1, v2);
return ans;
}
dfs(0);
if (ok.size() == 0) return false;
vector <int> a1;
for (int i = 1; i < ok.size(); i++) a1.push_back(mp[{ok[i - 1], ok[i]}]);
ans = a1;
int v1, v2, v3, x, y;
x = ok.back();
ok.pop_back();
y = a1.back();
v1 = adj[x][0].second;
v2 = adj[x][1].second;
v3 = adj[x][2].second;
if (v1 != y && v2 != y) get(ans, v1, v2);
else if (v1 == y) get(ans, v2, v3);
else get(ans, v1, v3);
reverse(a1.begin(), a1.end());
for (auto x : a1) ans.push_back(x);
map <int, int> hol;
for (auto x : ans) hol[x]++;
for (auto [x, y] : hol) if (y & 1) assert(false);
return ans;
}
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:59:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for (int i = 1; i < ok.size(); i++) a1.push_back(mp[{ok[i - 1], ok[i]}]);
| ~~^~~~~~~~~~~
# | 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... |