# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1028234 | 42kangaroo | Thousands Islands (IOI22_islands) | C++17 | 0 ms | 0 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 <variant>
#include <vector>
#include "bits/stdc++.h"
using namespace std;
using g_t = vector<vector<pair<int,int>>>;
int dfs(int n, int d, int p, g_t& g, vector<bool>& vis, vector<int>& re) {
vis[n] = true;
for (auto [ne, nu]: g[n]) {
if (vis[ne]) {
re.push_back(nu);
return ne;
}
int res = dfs(ne, nu, g, vis, re);
if (re.empty()) continue;
re.push_back(nu);
if (res == n) {
re.push_back(-1);
return -2;
}
return res;
}
return -2;
}
std::variant<bool, std::vector<int>> find_journey(
int N, int M, std::vector<int> U, std::vector<int> V) {
if (N == 2) {
vector<int> s0, s1;
for (int i = 0; i < M; ++i) {
if (U[i] == 0) s0.push_back(i);
else s1.push_back(i);
}
if (s0.size() >= 2 && s1.size() >= 1) {
return vector<int>{s0[0], s1[0], s0[1], s0[0], s1[0], s0[1]};
} else return false;
}
g_t g(N);
int s01, s10, s21, s02;
for (int i = 0; i < M; ++i) {
if (U[i] == 0 && V[i] == 1) s01 = i;
if (U[i] == 1 && V[i] == 0) s10 = i;
if (U[i] == 2 && V[i] == 1) s21 = i;
if (U[i] == 0 && V[i] == 2) s02 = i;
}
return vector<int>{s02, s21, s10, s01, s21, s02, s10, s01};
}