# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
786264 | vjudge1 | Thousands Islands (IOI22_islands) | C++17 | 26 ms | 5328 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);
}
if (S3) {
int x = 0, y = -1;
while (1) {
if (adj[x].size() < 2 - (y == -1)) {
return false;
}
if (adj[x].size() > 2 - (y == -1)) {
return true;
}
if (adj[x][0].second == (y ^ 1)) {
tie(x, y) = adj[x][1];
} else {
tie(x, y) = adj[x][0];
}
}
}
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... |