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<int> path;
vector<bool> visited;
vector<vector<int>> g;
vector<array<int, 2>> edges;
vector<int> double_links;
vector<int> result;
bool dfs(int node)
{
if (visited[node] || double_links[node] != -1)
return true;
visited[node] = true;
for (int edge : g[node])
{
path.pb(edge);
if(dfs(edges[edge][1]))
return true;
}
path.pp();
return false;
}
vector<int> create_double_links(vector<array<int, 2>> edges, int n, int m)
{
sort(edges.begin(), edges.end());
vector<int> double_links(n, -1);
for (int i = 0; i < m-1; i++)
if (edges[i] == edges[i+1])
for (int i = 0; i < 2; i++)
double_links[edges[i][i]] = edges[i][i^1];
return double_links;
}
variant<bool, vector<int>> find_journey(int n, int m, vector<int> u, vector<int> v)
{
return n > 2;
result.clear();
path.clear();
visited = vector<bool>(n, false);
edges = vector<array<int, 2>>(m);
for (int i = 0; i < m; i++)
cin >> edges[i][0] >> edges[i][1];
double_links = create_double_links(edges, n, m);
g = vector<vector<int>>(n);
for (int i = 0; i < m; i++)
g[edges[i][0]].pb(i);
if(dfs(0))
return result;
return 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... |