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 tuple<ll,ll,ll> PP;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<P> vp;
typedef vector<vp> vvp;
#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 fi first
#define se second
#define pb emplace_back
#define all(a) a.begin(),a.end()
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
#define N 300005
bool done[N],ok_c[N];
int seen1[N],cnt_seen1=-1,r[N];
vp g[N];
vi edges[N],tmp_c,tmp;
bool dfs1(ll i){
if(done[i])return false;
tmp.pb(i);
seen1[i]=cnt_seen1;
if(!ok_c[r[i]]){
tmp_c.pb(r[i]);
ok_c[r[i]]=true;
for(ll x:edges[r[i]])if(seen1[x]!=cnt_seen1){
if(!dfs1(x))return false;
}
}
for(auto x:g[i])if(seen1[x.fi]!=cnt_seen1){
if(ok_c[x.se]){
if(!dfs1(x.fi))return false;
}
else{
tmp_c.pb(x.se);
edges[x.se].pb(x.fi);
}
}
return true;
};
vector<int> find_reachable(vector<int> R, vector<int> u, vector<int> v, vector<int> c) {
ll n=R.size(),m=u.size();
vi ord(n);rep(i,n)ord[i]=i;random_shuffle(all(ord));
rep(i,n){
seen1[i]=-1;
done[i]=false;
ok_c[i]=false;
r[i]=R[i];
}
rep(i,m){
g[u[i]].pb(v[i],c[i]);
g[v[i]].pb(u[i],c[i]);
}
vi p(n,n+1);
for(ll s:ord)if(!done[s]){
cnt_seen1++;
if(dfs1(s)){
for(ll x:tmp)p[x]=tmp.size();
}
for(ll x:tmp_c){
edges[x].clear();
ok_c[x]=false;
}
tmp.clear();tmp_c.clear();
done[s]=true;
}
ll mi=n+1;
for(ll x:p)chmin(mi,x);
vector<int> ans(n);
rep(i,n)if(p[i]==mi)ans[i]=1;
return ans;
}
# | 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... |