Submission #1071755

#TimeUsernameProblemLanguageResultExecution timeMemory
1071755cpdreamerFriend (IOI14_friend)C++14
0 / 100
1 ms860 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...