# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
730420 | caganyanmaz | Thousands Islands (IOI22_islands) | C++17 | 37 ms | 7248 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 <bits/stdc++.h>
#define pb push_back
#define pp pop_back
using namespace std;
vector<array<int, 2>> edges;
vector<vector<int>> g;
vector<bool> visited;
vector<bool> remember;
vector<int> path;
vector<int> res;
bool dfs(int node)
{
if (visited[node])
{
for (int i : path)
res.pb(i);
int i;
for (i = 0; i < path.size() && edges[path[i]][0] != node; i++);
assert(i < path.size());
for (int j = i; j < path.size(); j++)
res.pb(path[j]+1);
for (int j = path.size()-1; j >= i; j--)
res.pb(path[j]);
for (int j = path.size()-1; j >= i; j--)
res.pb(path[j]+1);
for (int j = i-1; j >= 0; j--)
res.pb(path[j]);
return true;
}
visited[node] = true;
for (int edge : g[node])
{
if (remember[edges[edge][1]])
continue;
path.pb(edge);
if(dfs(edges[edge][1]))
return true;
}
visited[node] = false;
remember[node] = true;
return false;
}
variant<bool, vector<int>> find_journey(int n, int m, vector<int> u, vector<int> v)
{
edges = vector<array<int, 2>>(m);
g = vector<vector<int>>(n);
visited = vector<bool>(n);
remember = vector<bool>(n);
for (int i = 0; i < m; i+=2)
{
edges[i][0] = u[i], edges[i][1] = v[i];
g[u[i]].pb(i);
}
if(dfs(0))
return res;
return false;
}
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... |