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>
using namespace std;
constexpr int N_MAX = 100000;
set<pair<int, int>> g[N_MAX], rg[N_MAX];
void delete_node(int u)
{
vector<int> to_delete;
for (auto const &[v, i] : g[u])
rg[v].erase(make_pair(u, i));
for (auto const &[v, i] : rg[u])
{
g[v].erase(make_pair(u, i));
if (g[v].empty())
to_delete.push_back(v);
}
g[u].clear();
rg[u].clear();
for (auto const &v : to_delete)
delete_node(v);
}
variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V)
{
for (int i = 0; i < M; ++i)
g[U[i]].emplace(V[i], i), rg[V[i]].emplace(U[i], i);
for (int i = 0; i < N; ++i)
if (g[i].empty())
delete_node(i);
int x = 0;
while (g[x].size() == 1)
{
int y = g[x].begin()->first;
delete_node(x);
x = y;
}
return !g[x].empty();
}
# | 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... |