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 "keys.h"
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a; i<b; i++)
typedef vector<int>vi;
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)
typedef pair<int,int>pi;
#define fi first
#define se second
typedef vector<pi>vpi;
#define eb emplace_back
bool ckmin(int &x, int y){
int f=x>y;
x=min(x,y);
return f;
}
//-------
const int MX=3e5+10;
int N,M;
vpi adj[MX];
vi find_reachable(vi a, vi U, vi V, vi C){
N=sz(a); M=sz(U);
FOR(i,0,M){
int u=U[i], v=V[i];
adj[u].eb(v,C[i]);
adj[v].eb(u,C[i]);
}
vi ans;
int mn=2e9;
FOR(s,0,N){
vi vis(N,0);
vi vist(N,0);
queue<int>q; q.push(s);
int n=0;
vi vec;
while(sz(q)){
int u=q.front(); q.pop();
vis[u]=1;
vec.pb(u);
vist[a[u]]=1;
n++; if(n>mn) break;
for(int u: vec) for(auto it: adj[u]){
int v=it.fi, t=it.se;
if(vist[t] && !vis[v]){
q.push(v);
}
}
}
if(ckmin(mn,sz(vec))) ans={s};
else if(mn==sz(vec)) ans.pb(s);
}
vi res(N,0);
for(int x: ans) res[x]=1;
return res;
}
# | 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... |