#include "islands.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using lld = long double;
using ii = pair<int,int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<ii>;
using vpll = vector<pll>;
using vlld = vector<lld>;
// #define endl '\n'
#define all(x) x.begin(),x.end()
#define lsb(x) x&(-x)
#define gcd(a,b) __gcd(a,b)
#define sz(x) (int)x.size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fls cout.flush()
#define fore(i,l,r) for(auto i=l;i<r;i++)
#define fo(i,n) fore(i,0,n)
#define forex(i,r,l) for(auto i=r; i>=l;i--)
#define ffo(i,n) forex(i,n-1,0)
bool cmin(ll &a, ll b) { if(b<a){a=b;return 1;}return 0; }
bool cmax(ll &a, ll b) { if(b>a){a=b;return 1;}return 0; }
void valid(ll in) { cout<<((in)?"Yes\n":"No\n"); }
ll lcm(ll a, ll b) { return (a/gcd(a,b))*b; }
ll gauss(ll n) { return (n*(n+1))/2; }
const ll INF = 1e18;
const int N = 1005;
ll vis[N], dp[N], ans;
stack<ll> stk, rs;
vector<vector<array<ll, 2>>> gr;
vector<int> r;
void dfs (ll u, ll pr) {
stk.push(u);
vis[u] = 1;
for (auto [v, i]: gr[u]) {
if (vis[v]) {
ans = 1;
return;
} else {
if (dp[v]) continue;
dfs(v, i);
}
}
dp[u] = 1;
vis[u] = 0;
stk.pop();
rs.pop();
}
variant<bool, vector<int>> find_journey(
int n, int m, vector<int> u, vector<int> v) {
if (n == 2) {
vll ok[2];
fo (i, m) ok[u[i]].pb(i);
if (sz(ok[0]) < 2 || sz(ok[1]) < 1) return false;
vector<int> r;
r.pb(ok[0][0]);
r.pb(ok[1][0]);
r.pb(ok[0][1]);
r.pb(ok[0][0]);
r.pb(ok[1][0]);
r.pb(ok[0][1]);
return r;
}
gr = vector<vector<array<ll, 2>>>(n);
for (ll i = 0; i < m ; i += 2) {
gr[u[i]].pb({v[i], i});
}
ans = 0;
dfs(0, -1);
return (ans ? true : 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... |