# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
787562 | thimote75 | Thousands Islands (IOI22_islands) | C++17 | 33 ms | 6336 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;
using idata = vector<int>;
using igrid = vector<idata>;
using bdata = vector<bool>;
igrid roads;
bdata visited;
bdata visiting;
idata path;
bool dfs (int node) {
if (visiting[node]) {
path.push_back(node);
return true;
}
if (visited[node]) return false;
path.push_back(node);
visited[node] = true;
visiting[node] = true;
for (int next : roads[node]) if (dfs(next))
return true;
visiting[node] = false;
path.pop_back();
return false;
}
std::variant<bool, idata> find_journey(
int N, int M, idata U, idata V) {
roads.resize(N);
visited.resize(N); visiting.resize(N);
bool st3 = M % 2 == 0;
for (int i = 0; i < M; i ++)
roads[U[i]].push_back(V[i]);
for (int i = 0; i + 1 < M; i += 2)
st3 &= (U[i] == U[i + 1]) && (V[i] == V[i + 1]);
if (!dfs(0)) return false;
idata dpath;
idata cycle;
int joint = path[path.size() - 1];
bool f_joint = false;
for (int i = 0; i + 1 < path.size(); i ++) {
if (f_joint) cycle.push_back(path[i]);
else if (path[i] != joint) dpath.push_back(path[i]);
f_joint |= path[i] == joint;
}
idata answer;
if (st3) { // dpath + (joint + cycle) * 2 + (joint + cycle^-1) * 2 + joint + dpath^-1
for (int u : dpath) answer.push_back(u);
answer.push_back(joint);
for (int u : cycle) answer.push_back(u);
answer.push_back(joint);
for (int u : cycle) answer.push_back(u);
reverse(cycle.begin(), cycle.end());
answer.push_back(joint);
for (int u : cycle) answer.push_back(u);
answer.push_back(joint);
for (int u : cycle) answer.push_back(u);
answer.push_back(joint);
reverse(dpath.begin(), dpath.end());
for (int u : dpath) answer.push_back(u);
}
return answer;
}
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... |