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<bits/stdc++.h>
#include <variant>
#include <vector>
using namespace std;
#define sz(a) (int)(a.size())
#define pb push_back
#define fi first
#define se second
typedef pair<int,int> pii;
const int MAXN = 5e5+5;
bool dead[MAXN],mark[MAXN];
int outdeg[MAXN];
vector<pii>g[MAXN],gr[MAXN];
void upd(int v){
while(!g[v].empty() && dead[g[v].back().se])g[v].pop_back();
}
variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V){
for(int i=0;i<M;i++){
gr[V[i]].pb({U[i],i});
g[U[i]].pb({V[i],i});
outdeg[U[i]]++;
}
vector<int>del;
for(int i=0;i<N;i++){
//cout<<i<<" "<<sz(g[i])<<'\n';
if(g[i].empty()){
del.pb(i);
mark[i] = 1;
}
}
int cur = 0;
while(true){
if(mark[cur])return false;
while(!del.empty()){
vector<int>tmp;
for(int u:del){
//cout<<u<<'\n';
for(pii x:gr[u]){
int v = x.fi;
outdeg[v]--;
dead[x.se] = 1;
if(!outdeg[v]){
tmp.pb(v);
mark[v] = 1;
}
}
}
del = tmp;
}
if(mark[cur])return false;
int cnt = 0;
for(pii x:g[cur]){
if(!mark[x.fi])cnt++;
}
if(cnt > 1)return true;
if(cnt == 0)return false;
for(pii x:g[cur]){
if(!mark[x.fi]){
mark[cur] = 1;
cur = x.fi;
break;
}
}
}
}
# | 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... |