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;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<bool> vb;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,k,n) for(ll i=(ll)(k);i<(ll)(n);i++)
#define all(a) a.begin(),a.end()
#define fi first
#define se second
#define pb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
const ll inf=1001001001001;
#include "islands.h"
std::variant<bool, std::vector<int>> find_journey(int N, int M, std::vector<int> U, std::vector<int> V) {
vvp g(N),rg(N);
rep(i,M){
g[U[i]].pb(V[i],i);
rg[V[i]].pb(U[i],i);
}
vi cnt(N);rep(i,N)cnt[i]=g[i].size();
vb dead(N,false);
queue<ll> que;
auto f=[&](ll i){
que.push(i);
while(!que.empty()){
ll t=que.front();que.pop();
for(auto x:rg[t])if(!dead[x.fi]){
cnt[x.fi]--;
if(cnt[x.fi]==0){
dead[x.fi]=true;que.push(x.fi);
}
}
}
};
rep(i,N)if(!dead[i]&&cnt[i]==0){
dead[i]=true;f(i);
}
if(dead[0])return false;
ll cur=0;
while(true){
dead[cur]=true;f(cur);
vi nex;
for(auto x:g[cur])if(!dead[x.fi])nex.pb(x.fi);
if(nex.size()==0)return false;
if(nex.size()>1)return true;
cur=nex[0];
}
}
# | 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... |