You can treat the given network as a graph such that any 2 nodes sharing a friendship relation will be connected by an edge now in order to find the number of friend candidates for each user what you can do is to find the size of the fully connected component which contains a given node and then subtract all the friendship & blockship relations of that particular node which are also present in the same connected component. For example, consider the sample given in the problem
INPUT
10 9 3
10 1
6 7
8 2
2 5
8 4
7 3
10 9
6 4
5 8
2 6
7 5
3 1
OUTPUT:1 3 5 4 3 3 3 3 1 0
consider node number 6 the size of the connected component which contains it is 7 and it has 2 nodes in friendship relation (node 4 &7 ), it has a blockship relation with node number 2 and you cannot select the node 6 itself so the number of friend candidates for node 6 will be 7-2-1-1 =3
Check the implementation here
COMMENTED CODE
/*
_ __ _ _____ _____ _____
___ _ _| |__ ___ / _|_ __ ___ __ _| | __ |___ |___ |___ |
/ __| | | | '_ \ / _ \ |_| '__/ _ \/ _` | |/ / / / / / / /
| (__| |_| | |_) | __/ _| | | __/ (_| | < / / / / / /
\___|\__,_|_.__/ \___|_| |_| \___|\__,_|_|\_\ /_/ /_/ /_/
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vi;
typedef vector<pll> vpll;
typedef unordered_map <ll,ll> umap ;
//#pragma GCC optimize "trapv"
#define loop(i,a,b) for(ll i=a ;i<b;i++)
#define For(i,n) for(int i=0;i<(ll)n;i++)
#define Rev(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,n) for(int i=1;i<=n;++i)
#define F first
#define S second
#define pb push_back
#define em emplace_back
#define all(v) (v).begin(),(v).end()
#define mems(x, y) memset(x, y, sizeof(x))
#define sz(v) (v).size()
#define mp(a,b) make_pair(a,b)
#define pf(n) cout<<n<<"\n"
#define pff(n) cout << n << " " ;
long const M=1e9+7;
const long mxN =1e5+2 ;
const long mxNN =1e6+2 ;
int n,m,k,a,b,ans[mxN];// declarations ans[i] stores the ans for ith user
unordered_set<int>component ;// unordered set to store all the nodes of current component of analysis
bool visited[mxN] ;// boolean array to keep track of all visited nodes
vi friendship[mxN],blockship[mxN] ;//adjacency matrices storing all friendship nd blockship relations
// the following dfs returns the size of connected component in which th source is also it stores all the nodes of that component in unordered set
int dfs(int v){
int ans =1 ;// initialise for each node ans as 1 (node itself)
visited[v]=true ;component.insert(v) ;
for(int x :friendship[v])// for each adjacent node check if it is not visited yet then add its contribution
if(!visited[x])
ans+=dfs(x);
return ans ;// return the size
}
void solve(){
cin >> n >> m >> k ;// input stuff
For(i,m){
cin >>a >> b ;
friendship[a].em(b);
friendship[b].em(a) ;
}
For(i,k){
cin >>a>> b ;
blockship[a].em(b);
blockship[b].em(a) ;
}
mems(visited,0) ; // initialise all visited nodes as non visited
//Now traverse all nodes and check if it is visited or not if it is then you can be sure that it is part of some component
//that has already be processed else compute tha ans for all nodes of that particular component
for(int i =1;i<=n;i++){
if(visited[i])
continue ;
component.clear() ;// make sure to empty the set before moving ahead
int comp_size=dfs(i) ;// find size of the component which contains node i
for(int x :component){
ans[x]=comp_size-1 ;// first condition says that a!=b
for(int c:blockship[x])
if(component.count(c))ans[x]-- ;// second says that no blockship between a and b
ans[x]-=sz(friendship[x]) ;// lastly no friendship too
}
}
Rep(i,n)pff(ans[i]);// print the ans array
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve() ;
//ll t ; cin >> t ; while(t--)solve();
return 0;
}
Ping me if anything is not clear