# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
730416 | caganyanmaz | Thousands Islands (IOI22_islands) | C++17 | 1000 ms | 2097152 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<int> path;
vector<int> res;
bool dfs(int node)
{
if (visited[node])
{
for (int i : path)
res.pb(i);
int i;
for (i = 0; edges[path[i]][0] != node; i++);
for (int j = i; j < path.size(); j++)
res.pb(path[i]+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;
}
for (int edge : g[node])
{
path.pb(edge);
if(dfs(edges[edge][1]))
return 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);
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... |