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 mp(x...) array<int, 2>({x})
#define pb push_back
#include "islands.h"
using namespace std;
//#include "../debug.h"
#define debug(x...) void(42)
int n, m;
vector<int> u, v;
variant<bool, vector<int>> subtask1()
{
if (n <= 2)
return false;
array<array<int, 3>, 3> a;
for (int i = 0; i < m; i++)
if (u[i] <= 2 && v[i] <= 2)
a[u[i]][v[i]] = i;
debug(a);
return vector<int>({a[0][1], a[1][2], a[2][0], a[0][2], a[2][1], a[1][0], a[2][0], a[1][2], a[0][1], a[1][0], a[2][1], a[0][2]});
}
constexpr static int MXN = 1e5;
bitset<MXN> visited;
vector<array<int, 2>> g[MXN];
vector<int> res;
bool dfs(int node, int le)
{
visited[node] = true;
debug(node, g[node]);
if (g[node].size() > 2 || (g[node].size() > 1 && le < 0))
{
for (auto [c,e] : g[node])
{
if (e/2 == le/2)
continue;
res.pb(e);
res.pb(e^1);
}
for (auto [c, e] : g[node])
{
if (e/2 == le/2)
continue;
res.pb(e^1);
res.pb(e);
}
return true;
}
for (auto [c, e] : g[node])
{
debug(node, c, e, le);
if (!visited[c])
{
res.pb(e);
if (dfs(c, e))
{
res.pb(e);
return true;
}
res.pop_back();
}
}
return false;
}
static inline int get_reverse(int i)
{
return (i / 2) * 2 + 1 - (i&1);
}
variant<bool, vector<int>> subtask2()
{
if (dfs(0, -5))
return res;
return false;
}
bool dfs2(int node)
{
visited[node] = true;
for (auto [c,e]: g[node])
if (visited[c] || dfs2(c))
return true;
return false;
}
variant<bool, vector<int>> subtask3()
{
return dfs2(0);
}
variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V)
{
n = N;
m = M;
u = U;
v = V;
for (int i = 0; i < m; i++)
{
g[u[i]].pb(mp(v[i], i));
debug(i, u[i], v[i]);
}
if (u[0] == v[0])
return subtask3();
return subtask2();
assert(false);
}
# | 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... |