# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1084585 | SamueleVid | Rarest Insects (IOI22_insects) | C++17 | 0 ms | 0 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>
using namespace std;
constexpr int MAXN = 1e5 + 5;
vector<int> adj[MAXN];
bool v[MAXN];
bool ciclo = 0;
int dfs(int u, int p) {
if (v[u]) ciclo = 1;
v[u] = 1;
bool tolto_p = 0;
for (auto x : adj[u]) {
if (x == p && !tolto_p) {
tolto_p = 1;
continue;
}
dfs(x, u);
}
}
variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) {
fill(v, v + MAXN, 0);
for (int i = 0; i < M; i ++) {
adj[U[i]].push_back(V[i]);
}
dfs(0, -1);
return ciclo;
}