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 <variant>
#include<iostream>
#include <vector>
#include<cassert>
using namespace std;
using pii = pair<int, int>;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define PB push_back
#define F first
#define S second
const int MAXN = 100010;
int n, m, cur, stpos[MAXN];
bool vis[MAXN], blocked[MAXN], inst[MAXN];
vector<int> st, se;
vector<pii> g[MAXN];
bool dfs2(int v){
inst[v]=true;
vis[v]=true;
for(pii to:g[v]) if(!vis[to.F] && !blocked[to.F]) {
bool ret = dfs2(to.F);
if(ret) return true;
}
else if((inst[to.F] || stpos[to.F]!=-1) && !blocked[to.F] && to.S != se[cur]){
return true;
}
inst[v]=false;
return false;
}
int dfs1(int v){
stpos[v]=(int)st.size();
st.PB(v);
vis[v]=true;
for(pii to:g[v]) if(!vis[to.F] && !blocked[to.F]){
se.PB(to.S);
int ret = dfs1(to.F);
if(ret) return ret;
}
else if(stpos[to.F]!=-1){
while(cur<=stpos[to.F]){
bool ret = dfs2(st[cur]);
if(ret) return 1;
blocked[st[cur]]=true;
++cur;
}
}
if((int)st.size() <= cur+1) return 2;
st.pop_back();
se.pop_back();
stpos[v]=-1;
return 0;
}
variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) {
n=N, m=M;
forn(i, n) stpos[i]=-1;
forn(i, m) g[U[i]].PB({V[i], i});
int ret = dfs1(0);
if(ret==1){
vector<int> ans;
return ans;
}
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... |