# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
786276 | vjudge1 | Thousands Islands (IOI22_islands) | C++17 | 32 ms | 5448 KiB |
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> f0, f1;
for (int i = 0; i < M; i++) {
(U[i] == 0 ? f0 : f1).push_back(i);
}
if (f0.size() < 2 || f1.size() < 1) {
return false;
}
return vector{f0[0], f1[0], f0[1], f0[0], f1[0], f0[1]};
}
bool S3 = M % 2 == 0;
vector<vector<pair<int, int>>> adj(N);
for (int i = 1; i < M; i += 2) {
if (U[i - 1] != V[i] || V[i - 1] != U[i]) {
S3 = 0;
}
adj[U[i]].emplace_back(V[i], i);
adj[V[i]].emplace_back(U[i], i - 1);
}
if (S3) {
int x = 0, y = -1;
vector<int> p;
while (1) {
if (adj[x].size() < 2 - (y == -1)) {
return false;
}
if (adj[x].size() > 2 - (y == -1)) {
auto ans = p;
int u, v;
if (y == -1) {
u = adj[x][0].second;
v = adj[x][1].second;
} else {
u = adj[x][adj[x][0].second == (y ^ 1) ? 1 : 0].second;
v = adj[x][adj[x][2].second == (y ^ 1) ? 1 : 2].second;
}
ans.push_back(u);
ans.push_back(u ^ 1);
ans.push_back(v);
ans.push_back(v ^ 1);
ans.push_back(u ^ 1);
ans.push_back(u);
ans.push_back(v ^ 1);
ans.push_back(v);
for (int i = p.size() - 1; i >= 0; i--) {
ans.push_back(p[i] ^ 1);
}
return ans;
}
if (adj[x][0].second == (y ^ 1)) {
tie(x, y) = adj[x][1];
} else {
tie(x, y) = adj[x][0];
}
p.push_back(y);
}
}
int a, b, c, d;
for (int i = 0; i < M; i++) {
if (U[i] == 0) {
if (V[i] == 1) {
a = i;
}
if (V[i] == 2) {
c = i;
}
}
if (V[i] == 0) {
if (U[i] == 1) {
b = i;
}
if (U[i] == 2) {
d = i;
}
}
}
return vector{a, b, c, d, b, a, d, c};
}
Compilation message (stderr)
# | 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... |