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;
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
const int mxn=2000+5;
int n,m;
vector<pii>vtt[mxn];
int bfs(int u,vector<int> &r){
vector<queue<int>>arr(m+5);
queue<int>q;
vector<int>mp(m+5);
vector<int>color(n+5);
q.push(u);
mp[r[u]]=1;
int ans=1;
while(q.size()){
int u=q.front();
q.pop();
while(arr[r[u]].size()){
int x=arr[r[u]].front();
arr[r[u]].pop();
if(color[x]) continue;
ans++;
q.push(x);
mp[r[x]]=1;
color[x]=1;
}
for(pii p:vtt[u]){
int v=p.F,k=p.S;
if(color[v]) continue;
if(mp[k]){
ans++;
q.push(v);
mp[r[v]]=1;
color[v]=1;
}
else{
arr[k].push(v);
}
}
}
return ans;
}
vector<int> find_reachable(vector<int> r,vector<int> u,vector<int> v,vector<int> c) {
n=r.size();
m=u.size();
for(int i=0;i<m;i++){
vtt[u[i]].pb({v[i],c[i]});
vtt[v[i]].pb({u[i],c[i]});
}
int cnt=1e7;
vector<int>ans;
for(int i=0;i<n;i++){
int x=bfs(i,r);
cnt=min(x,cnt);
ans.pb(x);
}
for(int i=0;i<n;i++){
if(ans[i]==cnt){
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... |