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;
variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) {
if (N == 2) {
vector<int> a, b;
for (int i = 0; i < M; i++) {
if (U[i] == 0) {
a.push_back(i);
} else {
b.push_back(i);
}
}
if (a.size() >= 2 && b.size() >= 1) {
return vector{a[0], b[0], a[1], a[0], b[0], a[1]};
} else {
return false;
}
}
bool subtask3 = 0;
bool subtask4 = 0;
if (M % 2 == 0) {
subtask3 = 1;
subtask4 = 1;
for (int i = 0; i < M; i += 2) {
if (U[i] != V[i + 1] || V[i] != U[i + 1]) {
subtask3 = 0;
}
if (U[i] != U[i + 1] || V[i] != V[i + 1]) {
subtask4 = 0;
}
}
}
vector<vector<pair<int, int>>> adj(N);
for (int i = 0; i < M; i++) {
adj[U[i]].emplace_back(V[i], i);
}
if (subtask3) {
vector<int> ans;
int x = 0, p = -1;
while (1) {
vector<array<int, 2>> f;
for (auto [y, z] : adj[x]) {
if (y != p) {
f.push_back({y, z});
}
}
if (f.empty()) {
return false;
}
if (f.size() == 1) {
ans.push_back(f[0][1]);
p = x;
x = f[0][0];
continue;
}
auto v = vector(ans.rbegin(), ans.rend());
vector<int> s(M);
ans.push_back(f[0][1]);
ans.push_back(f[0][1] ^ 1);
ans.push_back(f[1][1]);
ans.push_back(f[1][1] ^ 1);
ans.push_back(f[0][1] ^ 1);
ans.push_back(f[0][1]);
ans.push_back(f[1][1] ^ 1);
ans.push_back(f[1][1]);
ans.insert(ans.end(), v.begin(), v.end());
return ans;
}
}
if (subtask4) {
vector<int> p, ans, vis(N);
auto dfs = [&](auto dfs, int x) -> bool {
vis[x] = 1;
for (auto [y, z] : adj[x]) {
if (vis[y] == 1) {
p.push_back(z);
int t = 0, q = 0;
while (t != y) {
t ^= U[p[q]] ^ V[p[q]];
q++;
}
for (int i = 0; i < q; i++) {
ans.push_back(p[i]);
}
for (int i = q; i < p.size(); i++) {
ans.push_back(p[i]);
}
for (int i = q; i < p.size(); i++) {
ans.push_back(p[i] ^ 1);
}
for (int i = p.size() - 1; i >= q; i--) {
ans.push_back(p[i]);
}
for (int i = p.size() - 1; i >= q; i--) {
ans.push_back(p[i] ^ 1);
}
for (int i = q - 1; i >= 0; i--) {
ans.push_back(p[i]);
}
return 1;
}
if (!vis[y]) {
p.push_back(z);
if (dfs(dfs, y)) {
return 1;
}
p.pop_back();
}
}
vis[x] = 2;
return 0;
};
if (dfs(dfs, 0)) {
return ans;
} else {
return false;
}
}
int s[3][3];
for (int i = 0; i < M; i++) {
if (U[i] < 3 && V[i] < 3) {
s[U[i]][V[i]] = i;
}
}
return vector{s[0][1], s[1][2], s[2][0], s[0][2], s[2][1], s[1][0], s[2][0], s[1][2], s[0][1], s[1][0], s[2][1], s[0][2]};
}
Compilation message (stderr)
islands.cpp: In instantiation of 'find_journey(int, int, std::vector<int>, std::vector<int>)::<lambda(auto:23, int)> [with auto:23 = find_journey(int, int, std::vector<int>, std::vector<int>)::<lambda(auto:23, int)>]':
islands.cpp:114:23: required from here
islands.cpp:86:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | for (int i = q; i < p.size(); i++) {
| ~~^~~~~~~~~~
islands.cpp:89:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | for (int i = q; i < p.size(); 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... |