# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
787589 | thimote75 | Thousands Islands (IOI22_islands) | C++17 | 157 ms | 38060 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 graph = vector<vector<pair<pair<int, bool>, int>>>;
using bdata = vector<bool>;
using bgrid = vector<bdata>;
graph roads;
bgrid visited;
bgrid visiting;
bdata used;
idata path;
bool dfs (int node, int type, int last) {
if (visited[node][type] && !visiting[node][type]) return false;
if (visiting[node][type]) {
if (type == 1) return true;
type ++;
if (visited[node][type]) return false;
}
visiting[node][type] = true;
visited [node][type] = true;
for (const auto &road : roads[node]) {
int id = road.first.first;
int next = road.second;
if (used[id] != road.first.second || last == id) continue ;
used[id] = !road.first.second;
if (dfs(next, type, id))
return true;
used[id] = road.first.second;
}
visiting[node][type] = false;
return false;
}
std::variant<bool, idata> find_journey(
int N, int M, idata U, idata V) {
roads.resize(N);
visited.resize(N, bdata(2)); visiting.resize(N, bdata(2));
used.resize(M);
bool st3 = M % 2 == 0;
for (int i = 0; i < M; i ++) {
roads[U[i]].push_back({ {i, false}, V[i] });
roads[V[i]].push_back({ {i, true }, U[i] });
}
if (!dfs(0, 0, -1)) return false;
return true;
}
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... |