# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
825928 | LittleCube | Thousands Islands (IOI22_islands) | C++17 | 32 ms | 10648 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>
#define ll long long
#define pii pair<int, int>
#define F first
#define S second
using namespace std;
namespace
{
int K;
vector<int> path, vis, use;
vector<pii> E[100000], R[100000];
int dfs(int u)
{
vis[u] = 1;
path.emplace_back(u);
for (auto [v, i] : E[u])
if (vis[v] == 0 && !use[i])
{
use[i] = 1;
int res = dfs(v);
if (res != -1)
return res;
use[i] = 0;
}
else if (vis[v] == 1 && !use[i])
{
use[i] = 1;
return v;
}
path.pop_back();
return -1;
}
}
variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V)
{
for (int i = 0; i < M; i++)
E[U[i]].emplace_back(pii(V[i], i));
vis.resize(N, 0);
use.resize(M, 0);
int res = dfs(0);
path.emplace_back(res);
vector<int> ch1, cyc1;
{
int i = 0;
for (; i < path.size(); i++)
{
ch1.emplace_back(i);
if (path[i] == res)
break;
}
i++;
for (; i < path.size(); i++)
cyc1.emplace_back(i);
path.clear();
}
for (int i : ch1)
{
int res = dfs(i);
if (res >= 0)
return true;
vis[i] = 2;
}
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... |