이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(ll i=a,ioi=b;i<ioi;i++)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define imp(v) {for(auto fjhg:v)cout<<fjhg<<" ";cout<<"\n";}
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
const ll MAXN=3e5+5;
ll uf[MAXN],viv[MAXN];
vector<ll>nxt[MAXN];
set<ll>col[MAXN];
map<ll,vector<ll>>mp[MAXN];
ll find(ll x){return uf[x]<0?x:uf[x]=find(uf[x]);}
void join(ll x, ll y){
x=find(x),y=find(y);
if(x==y)return;
if(viv[y]){viv[x]=0;return;}
if(SZ(nxt[x])<SZ(nxt[y]))swap(nxt[x],nxt[y]);
for(auto i:nxt[y])nxt[x].pb(i);; nxt[y].clear();
if(sizeof(col[x])+sizeof(mp[x])<sizeof(col[y])+sizeof(mp[y]))
swap(x,y);
// if(sizeof(mp[x])<sizeof(mp[y]))swap(mp[x],mp[y]);
for(auto i:col[y]){
col[x].insert(i);
for(auto j:mp[x][i])nxt[x].pb(j);
mp[x][i].clear();
}
col[y].clear();
for(auto &[c,v]:mp[y]){
auto &u=mp[x][c];
// if(SZ(u)<SZ(v))swap(u,v);
ll flag=col[x].count(c);
for(auto i:v){
if(flag)nxt[x].pb(i);
else u.pb(i);
}
v.clear();
}
// mp[y].clear();
if(uf[x]>uf[y])swap(x,y);
uf[x]+=uf[y]; uf[y]=x;
}
vector<int> find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c){
ll n=SZ(r);
mset(uf,-1);
fore(i,0,n)viv[i]=1;
fore(i,0,n)col[i]={r[i]};
auto add_edge=[&](ll u, ll v, ll c){
if(r[u]==c)nxt[u].pb(v);
else mp[u][c].pb(v);
};
fore(i,0,SZ(u)){
add_edge(u[i],v[i],c[i]);
add_edge(v[i],u[i],c[i]);
}
fore(x,0,n){
while(viv[find(x)]&&SZ(nxt[x])){
// fore(i,0,n)if(find(i)==find(x))cout<<i<<" ";
// cout<<"\n";
// cout<<"col ";;for(auto i:col[x])cout<<i<<" ";;cout<<"\n";
auto y=nxt[x].back(); nxt[x].pop_back();
join(x,y);
}
}
ll res=n+5;
vector<vector<ll>>cand(n+1);
fore(x,0,n)if(viv[find(x)]){
ll q=-uf[find(x)];
cand[q].pb(x);
res=min(res,q);
}
vector<int>ret(n);
for(auto i:cand[res])ret[i]=1;
return ret;
}
# | 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... |