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 "friend.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <utility>
#define V vector
#define F first
#define S second
#define P pair
#define pb push_back
#define all(v) v.begin(),v.end()
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;
V<int>adj[(int)1001];
void dfs(int n,bool vis[],V<int>&vp){
if(vis[n])return;
vis[n]=true;
vp.pb(n);
for(auto u:adj[n]) {
dfs(u, vis,vp);
}
}
bool custom(P<int,int>a,P<int,int>b){
return a.S<=b.S;
}
int findSample(int n,int confidence[],int host[],int protocol[]){
for(int i=1;i<n;i++){
if(protocol[i]==0){
adj[host[i]].pb(i);
adj[i].pb(host[i]);
}
else{
for(auto u:adj[host[i]]){
adj[u].pb(i);
adj[i].pb(u);
}
}
}
bool vis[n];
memset(vis,false,sizeof(vis));
V<V<int>>component;
for(int i=0;i<n;i++){
if(!vis[i]){
V<int>vp;
dfs(i,vis,vp);
component.pb(vp);
}
}
int s=0;
for(auto u:component){
V<P<int,int>>v;
for(auto x:u){
v.pb({x,adj[x].size()});
}
sort(all(v),custom);
set<int>st;
for(auto x:v){
if(st.count(x.F))continue;
s++;
for(auto vertex:adj[x.F]){
st.insert(vertex);
}
}
}
return s;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |