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>
#define mp make_pair
#define ff first
#define ss second
#define sz(x) (ll)(x).size()
#define all(x) x.begin(),x.end()
#define all_r(x) x.rbegin(),x.rend()
#define clr(a) memset((a),0,sizeof(a))
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef pair<ll,ll> pl;
typedef vector<ll> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef priority_queue<ll,vl,greater<ll>> pqg;
int R[300000];
vpi adj[300000];
set<int>st[300000],key;
void find(int k,int ind){
st[ind].ins(k);
key.ins(R[k]);
for(int i:st[ind]){
for(auto it:adj[i]){
if(st[ind].count(it.ff)==1 || key.count(it.ss)==0)continue;
find(it.ff,ind);
return;
}
}
}
vector<int> find_reachable(vector<int> r,vector<int> u,vector<int> v,vector<int> c){
int n=sz(r);
int m=sz(u);
vector<int> ans(n,1);
for(int i=0;i<n;i++)R[i]=r[i];
for(int i=0;i<m;i++){
adj[u[i]].pb({v[i],c[i]});
adj[v[i]].pb({u[i],c[i]});
}
int res=INT_MAX;
for(int i=0;i<n;i++){
key.clear();
for(auto it:adj[i]){
if(r[i]==it.ss && ans[it.ff]!=1){
for(int j:st[it.ff])st[i].ins(j);
}
}
find(i,i);
ans[i]=sz(st[i]);
if(res>ans[i])res=ans[i];
}
for(int i=0;i<n;i++){
if(ans[i]==res)ans[i]=1;
else ans[i]=0;
}
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... |