Problem:
 Score : 400 points    Problem Statement An SNS has N users - User 1 , User 2 , \cdots , User N .  Between these N users, there are some relationships - M  friendships and K  blockships .  For each i = 1, 2, \cdots, M , there is a bidirectional friendship between User A_i and User B_i .  For each i = 1, 2, \cdots, K , there is a bidirectional blockship between User C_i and User D_i .  We define User a to be a friend candidate for User b when all of the following four conditions are satisfied:   a \neq b .  There is not a friendship between User a and User b .  There is not a blockship between User a and User b .  There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a , c_L = b , and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1 .   For each user i = 1, 2, ... N , how many friend candidates does it have?      Constraints  All values in input are integers.  2 ≤ N ≤ 10^5  0 \leq M \leq 10^5  0 \leq K \leq 10^5  1 \leq A_i, B_i \leq N  A_i \neq B_i  1 \leq C_i, D_i \leq N  C_i \neq D_i  (A_i, B_i) \neq (A_j, B_j) (i \neq j)  (A_i, B_i) \neq (B_j, A_j)  (C_i, D_i) \neq (C_j, D_j) (i \neq j)  (C_i, D_i) \neq (D_j, C_j)  (A_i, B_i) \neq (C_j, D_j)  (A_i, B_i) \neq (D_j, C_j)         Input Input is given from Standard Input in the following format:  N  M  K  A_1  B_1  \vdots  A_M  B_M  C_1  D_1  \vdots  C_K  D_K       Output Print the answers in order, with space in between.        Sample Input 1 4 4 1
2 1
1 3
3 2
3 4
4 1      Sample Output 1 0 1 0 1  There is a friendship between User 2 and 3 , and between 3 and 4 . Also, there is no friendship or blockship between User 2 and 4 . Thus, User 4 is a friend candidate for User 2 .  However, neither User 1 or 3 is a friend candidate for User 2 , so User 2 has one friend candidate.       Sample Input 2 5 10 0
1 2
1 3
1 4
1 5
3 2
2 4
2 5
4 3
5 3
4 5      Sample Output 2 0 0 0 0 0  Everyone is a friend of everyone else and has no friend candidate.       Sample Input 3 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      Sample Output 3 1 3 5 4 3 3 3 3 1 0

Solution (Python):
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.par = [-1] * n
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.find(x) > self.find(y):
            x, y = y, x
        self.par[x] += self.par[y]
        self.par[y] = x
    def size(self, x):
        return -self.par[(self.find(x))]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def roots(self):
        return [i for i, x in enumerate(self.par) if x < 0]
    def group_count(self):
        return len(self.roots())
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n, m, k = map(int, input().split())
a, b = [0] * m, [0] * m
c, d = [0] * k, [0] * k

direct =[[] for _ in range(n)]
uf = UnionFind(n)

for i in range(m):
    a[i], b[i] = map(int, input().split())
    a[i] -= 1
    b[i] -= 1
    direct[a[i]].append(b[i])
    direct[b[i]].append(a[i])
    uf.union(a[i], b[i])

for i in range(k):
    c[i], d[i] = map(int, input().split())
    c[i] -= 1
    d[i] -= 1
    if uf.same(c[i], d[i]):
        direct[c[i]].append(d[i])
        direct[d[i]].append(c[i])

ans = [0] * n
for i in range(n):
    ans[i] = uf.size(i) - len(direct[i]) - 1

print(*ans)

Solution (Python):
from sys import stdin


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parent = [i for i in range(n)]  
        self.rank = [1] * n  
        self.size = [1] * n  

    def find(self, x):  
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])  
            return self.parent[x]

    def unite(self, x, y):  
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                self.parent[x] = y
                self.size[y] += self.size[x]
            else:
                self.parent[y] = x
                self.size[x] += self.size[y]
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1

    def is_same(self, x, y):  
        return self.find(x) == self.find(y)

    def group_size(self, x):  
        return self.size[self.find(x)]

    def group_members(self, x):  
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):  
        return [i for i, x in enumerate(self.parent) if i == x]

    def group_count(self):  
        return len(self.roots())

    def all_group_members(self):  
        return {r: self.group_members(r) for r in self.roots()}

    def __str__(self):  
        return '\n'.join('{}: {}'.format(r, self.group_members(r)) for r in self.roots())


def get_result(data):
    N, M, K = data[0]
    A, B = [0] * M, [0] * M
    C, D = [0] * K, [0] * K
    direct = [[] for _ in range(N)]  
    uf = UnionFind(N)

    for i in range(M):
        A[i], B[i] = data[1+i]
        
        A[i] -= 1
        B[i] -= 1
        direct[A[i]].append(B[i])
        direct[B[i]].append(A[i])
        uf.unite(A[i], B[i])

    for i in range(K):
        C[i], D[i] = data[1+M+i]
        
        C[i] -= 1
        D[i] -= 1
        if uf.is_same(C[i], D[i]):
            direct[C[i]].append(D[i])
            direct[D[i]].append(C[i])

    ans = [0] * N
    for i in range(N):
        ans[i] = uf.group_size(i) - len(direct[i]) - 1
    return ' '.join(list(map(str, ans)))


if __name__ == '__main__':
    raw_data = [val.rstrip('\n') for val in stdin.readlines()]
    data = [list(map(int, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)

Solution (Python):
class Unionroot:
    def __init__(self, n=0):
        self.d = [-1]*n

    def root(self, x):
        if self.d[x] < 0:
            return x
        self.d[x] = self.root(self.d[x])
        return self.d[x]

    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return False
        if x > y:
            x, y = y, x
        self.d[x] += self.d[y]
        self.d[y] = x
        return True

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def size(self, x):
        return -self.d[self.root(x)]

deg = [0] * 100005
to = [[] for i in range(100005)]

n, m, k = map(int, input().split())
uf = Unionroot(n)

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    deg[a] += 1
    deg[b] += 1
    uf.unite(a, b)

for i in range(k):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)

ret = []
for i in range(n):
    ans = uf.size(i) - 1 - deg[i]
    for u in to[i]:
        if uf.same(i, u):
            ans -= 1
    ret.append(ans)
print(' '.join([str(r) for r in ret]))

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

class UnionFind:
    def __init__(self, size):
        self.table = [-1 for _ in range(size)]

    def find(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]

    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] <= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        return False

    def subsetall(self):
        a = []
        for i in range(len(self.table)):
            if self.table[i] < 0:
                a.append((i, -self.table[i]))
        return a

def main():
    n,m,k = LI()
    ab = [LI_() for _ in range(m)]
    cd = [LI_() for _ in range(k)]
    e = collections.defaultdict(set)
    uf = UnionFind(n)
    for a,b in ab:
        e[a].add(b)
        e[b].add(a)
        uf.union(a,b)
    for c,d in cd:
        e[c].add(d)
        e[d].add(c)

    r = []
    for i in range(n):
        t = uf.find(i)
        s = -uf.table[t] - 1
        for j in e[i]:
            if uf.find(j) == t:
                s -= 1
        r.append(s)

    return JA(r, " ")


print(main())

Solution (Python):
class UnionFind():
    def __init__(self,num):
        self.n = num         
        self.parents = [-1 for i in range(self.n)]
          

    
    def find(self,x):
        if self.parents[x]<0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x]) 
                
            return self.parents[x]

    
    
    def union(self,x,y):
        xx=self.find(x)  
        yy=self.find(y)  
        if xx==yy:
            return     
        else:
            size_xx=abs(self.parents[xx]) 
            size_yy=abs(self.parents[yy]) 
            if size_xx>size_yy:
                xx,yy=yy,xx  

            self.parents[yy]+=self.parents[xx] 
            self.parents[xx]=yy   

    
    def size(self,x):
        xx=self.find(x)
        return abs(self.parents[xx])

    
    def same(self,x,y):
        return True if self.find(x)==self.find(y) else False

    
    def members(self,x):
        xx=self.find(x)
        return [i for i in range(self.n) if self.find(i)==xx]
             

    
    def roots(self):
        return [i for i,x in enumerate(self.parents) if x < 0]
        

    
    def all_group_members(self):
        return {r:self.members(r) for r in self.roots()}

    
    def state_grouping(self):
        return list(self.all_group_members().values())

    
    def __str__(self):
        return "\n".join("{}: {}".format(r,self.members(r)) for r in self.roots())
        
        
        
        


n,m,k=map(int,input().split())


uf=UnionFind(n)


G=[]
B=[]
for i in range(m):
    a,b=map(int,input().split())
    a,b=a-1,b-1
    G.append([a,b])
    uf.union(a,b)
for i in range(k):
    a,b=map(int,input().split())
    a,b=a-1,b-1
    B.append([a,b])

ans=[uf.size(i)-1 for i in range(n)] 
for a,b in G:
    ans[a]-=1 ; ans[b]-=1
for a,b in B:
    if uf.same(a,b):
        ans[a]-=1 ; ans[b]-=1

print(*ans)

Solution (Python):





from collections import deque

n, m, k = map(int, input().split())

adj = {a: [] for a in range(1, n+1)}
for i in range(m):
    a, b = map(int, input().split())
    adj[a].append(b)
    adj[b].append(a)



connOf = {}
for a in range(1, n+1):
    if a in connOf:
        continue
    conn = set()
    queue = deque()
    queue.append(a)
    while len(queue) > 0:
        p = queue.popleft()
        if p not in conn:
            conn.add(p)
            connOf[p] = conn
            queue.extend(adj[p])



block = {a: [] for a in range(1, n+1)}
for i in range(k):
    c, d = map(int, input().split())
    if c in connOf[d]:
        block[c].append(d)
        block[d].append(c)



nCandidate = [len(connOf[a]) - 1 - len(adj[a]) - len(block[a])
  for a in range(1, n+1)]
print(' '.join(map(str, nCandidate)))

Solution (Python):
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

N, M, K = map(int, input().split())


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


friend_checker = UnionFind(N)
direct_friends = [0 for _ in range(N)]

for _ in range(M):
    A, B = map(int, input().split())
    friend_checker.union(A - 1, B - 1)
    direct_friends[A - 1] += 1
    direct_friends[B - 1] += 1

block = [[] for _ in range(N)]
for _ in range(K):
    C, D = map(int, input().split())
    block[C - 1].append(D - 1)
    block[D - 1].append(C - 1)

for i in range(N):
    ans = friend_checker.size(i) - direct_friends[i] - 1
    for l in block[i]:
        if friend_checker.same(i, l):
            ans -= 1
    print(ans)

Solution (Python):
import math
import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
mod = 10**9 + 7 
sys.setrecursionlimit(1000010)

N,M,K = nm()



par=[-1] * N  


def find(x):  
  if par[x]<0:  
    return x    
  else:
    par[x]=find(par[x])  
        
        
    return par[x]


def unite(x,y):
  x=find(x)  
  y=find(y)  
  if x==y:   
    return False
  else:  
    if par[x]>par[y]: 
      
      
      x,y=y,x
    par[x]+=par[y]  
    par[y]=x  
       
       
    return True

def same(x,y):
  return find(x)==find(y)

def size(x):
  return -par[find(x)]

links=[0]*N   
F = [0]* N 
for _ in range(M):
    A,B = nm()
    unite(A-1,B-1)
    links[A-1] +=1 
    links[B-1] +=1

for _ in range(K):
    C,D = nm()
    if same(C-1,D-1):
        links[C-1]+=1
        links[D-1]+=1

for i in range(N):
    F[i] = size(i) - 1 - links[i]
print(*F)

Solution (Python):
def get_root(s):
    if s != root[s]:
        root[s] = get_root(root[s])
        return root[s]
    return s

def unite(s, t):
    root_s = get_root(s)
    root_t = get_root(t)
    if not root_s == root_t:
        if rank[s] == rank[t]:
            root[root_t] = root_s
            rank[root_s] += 1
            union_count[root_s] += union_count[root_t]
        elif rank[s] > rank[t]:
            root[root_t] = root_s
            union_count[root_s] += union_count[root_t]
        else:
            root[root_s] = root_t
            union_count[root_t] += union_count[root_s]

def same(s, t):
    if get_root(s) == get_root(t):
        return True
    else:
        return False

n, m, k = map(int, input().split())
root = [i for i in range(n)]
rank = [1 for _ in range(n)]
union_count = [1 for _ in range(n)]
friend_count = [0] * n
for _ in range(m):
    a, b = map(int, input().split())
    unite(a - 1, b - 1)
    friend_count[a - 1] += 1
    friend_count[b - 1] += 1
ans = [-1] * n
for _ in range(k):
    c, d = map(int, input().split())
    if same(c - 1, d - 1):
        ans[c - 1] -= 1
        ans[d - 1] -= 1
for i in range(n):
    r = get_root(i)
    ans[i] += union_count[r] - friend_count[i]
print(" ".join(map(str, ans)))

Solution (Python):

import sys




class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        
    def find(self, x): 
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y): 
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return
        
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x): 
        return -self.parents[self.find(x)]
        
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def solve(N: int, M: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]", D: "List[int]"):

    adjacency_list = [[] for _ in range(N+1)]
    uf = UnionFind(N+1)
    for i in range(M):
        adjacency_list[A[i]].append(B[i])
        adjacency_list[B[i]].append(A[i])
        uf.union(A[i],B[i])
    
    answer = []
    block_count = [0]*(N+1) 
    for k in range(K):
        if uf.same(C[k],D[k]):
            block_count[C[k]] += 1
            block_count[D[k]] += 1
        

    for i in range(1,N+1):
        size = uf.size(i) 
        answer.append(size-len(adjacency_list[i])-block_count[i]-1)
    print(*answer)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    M = int(next(tokens))  
    K = int(next(tokens))  
    A = [int()] * (M)  
    B = [int()] * (M)  
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    C = [int()] * (K)  
    D = [int()] * (K)  
    for i in range(K):
        C[i] = int(next(tokens))
        D[i] = int(next(tokens))
    solve(N, M, K, A, B, C, D)

if __name__ == '__main__':
    main()

Solution (Python):


import sys

def main():
    sys.setrecursionlimit(1000000)
    n, m, k = map(int, input().split())
    friends = [set() for i in range(n)]
    blocks = [set() for i in range(n)]
    parents = [i for i in range(n)]
    for i in range(m):
        a, b = map(int, input().split())
        friends[a - 1].add(b - 1)
        friends[b - 1].add(a - 1)
        unite(a - 1, b - 1, parents)
    for i in range(k):
        c, d = map(int, input().split())
        blocks[c - 1].add(d - 1)
        blocks[d - 1].add(c - 1)
    groups = [set() for i in range(n)]
    for i in range(n):
        p = find(i, parents)
        groups[p].add(i)
    res = []
    for i in range(n):
        p = find(i, parents)
        res.append(len(groups[p]) - len(friends[i]) - len(groups[p] & blocks[i]) - 1)
    print(" ".join([str(x) for x in res]))

def unite(x, y, parents):
    px = find(x, parents)
    py = find(y, parents)
    parents[py] = px

def find(x, parents):
    if parents[x] == x:
        return x
    fx = find(parents[x], parents)
    parents[x] = fx
    return fx

if __name__ == "__main__":
    main()

Solution (Python):


import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

from collections import defaultdict

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self._size = [1 for _ in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
        
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self._size[y] += self._size[x]
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self._size[x] += self._size[y]
    
    def size(self, x):
        x = self.find(x)
        return self._size[x]

    def same(self, x, y):
        return self.find(x) == self.find(y)

n, m, k = na()
ab = nan(m)
cd = nan(k)

friend = defaultdict(int)
uf = UnionFind(n)

for i in range(m):
    a, b = ab[i]
    a -= 1
    b -= 1
    uf.unite(a, b)
    friend[a] += 1
    friend[b] += 1

block = defaultdict(list)
for i in range(k):
    c, d = cd[i]
    c -= 1
    d -= 1
    block[c].append(d)
    block[d].append(c)
ans = []
for i in range(n):
    bf = 0
    for j in block[i]:
        if uf.same(i, j):
            bf += 1
    ans.append(uf.size(i) - friend[i] - bf - 1)

print(*ans)

Solution (Python):
N, M, K = map(int, input().split())
friend = [[] for _ in range(N+1)]
block = [[] for _ in range(N+1)]

for i in range(M):
  A,B = map(int, input().split())
  friend[A].append(B)
  friend[B].append(A)

for i in range(K):
  C,D = map(int, input().split())
  block[C].append(D)
  block[D].append(C)




grouping = [False]*(N+1)

grouping[0] = True
group = [0]*(N+1)
g_num = 0
g_cnt = []
for i in range(1,N+1):
  cnt = 0
  if grouping[i] == True:
    continue 
  group[i] = g_num
  grouping[i] = True
  
  
  stack = [i]
  
  while len(stack)>0:
    
    
    p = stack.pop()
    for f in friend[p]:
      
      if grouping[f]==False:
        
        stack.append(f)
        group[f]=g_num
        grouping[f] =True
        cnt += 1
  g_num += 1
  g_cnt.append(cnt)
  
ans = []
for i in range(1,N+1):
  c = g_cnt[group[i]]-len(friend[i])
  for b in block[i]:
    if group[b]==group[i]:
      c -= 1
  ans.append(c)
print(*ans)

Solution (Python):

def root(x):
    while par[x] >= 0:
        x = par[x]
    return x


def unite(x,y):
    rx = root(x)
    ry = root(y)
    if rx != ry:
        if rx > ry:
            rx,ry = ry,rx
        par[rx] += par[ry]
        par[ry] = rx


def same(x,y):
    rx = root(x)
    ry = root(y)
    return rx == ry


def size(x):
    return -par[root(x)]


N,M,K = map(int,input().split())
par = [-1]*N
g = [[] for _ in range(N)]
for i in range(M):
    A,B = map(int,input().split())
    A,B = A-1,B-1
    unite(A,B)
    g[A].append(B)
    g[B].append(A)

for i in range(K):
    C,D = map(int,input().split())
    C,D = C-1,D-1
    if same(C,D):
        g[C].append(D)
        g[D].append(C)

for i in range(N):
    print(size(i)-len(g[i])-1,end=' ')

Solution (Python):
class UnionFind:
    def __init__(self,n):
        self.n=n
        self.parents=[-1]*n
        self.rank=[0]*n

    def find(self,x):
        if self.parents[x]<0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]

    def union(self,x,y):
        x=self.find(x)
        y=self.find(y)

        if x==y:
            return 

        if self.rank[x]<self.rank[y]:
            self.parents[y]+=self.parents[x]
            self.parents[x]=y
        else:
            self.parents[x]+=self.parents[y]
            self.parents[y]=x

            if self.rank[x]==self.rank[y]:
                self.rank[x]+=1

    def are_same(self,x,y):
        return self.find(x)==self.find(y)

    def element_count(self,x):
        x=self.find(x)
        return -self.parents[x]

from sys import stdin
def main():
    
    readline=stdin.readline
    N,M,K=map(int,readline().split())
    
    t=UnionFind(N)
    fb=[set() for _ in range(N)]
    for _ in range(M):
        a,b=map(int,readline().split())
        t.union(a-1,b-1)
        if b-1 not in fb[a-1]:
            fb[a-1].add(b-1)
        if a-1 not in fb[b-1]:
            fb[b-1].add(a-1)
    
    for _ in range(K):
        c,d=map(int,readline().split())
        if t.are_same(c-1,d-1):
            if d-1 not in fb[c-1]:
                fb[c-1].add(d-1)
            if c-1 not in fb[d-1]:
                fb[d-1].add(c-1)

    res=[0]*N
    for i in range(N):
        res[i]=t.element_count(i)-1-len(fb[i])

    print(*res)

if __name__=="__main__":
    main()

Solution (Python):
from collections import defaultdict


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


if __name__ == '__main__':
    n, m, k = list(map(int, input().split()))
    friends = UnionFind(n)
    ng_dict = defaultdict(list)

    for i in range(m):
        data = list(map(int, input().split()))
        x = data[0] - 1
        y = data[1] - 1

        friends.union(x, y)
        ng_dict[x].append(y)
        ng_dict[y].append(x)

    for i in range(k):
        data = list(map(int, input().split()))
        x = data[0] - 1
        y = data[1] - 1

        if friends.same(x, y):
            ng_dict[x].append(y)
            ng_dict[y].append(x)

    for i in range(n):
        print(friends.size(i) - len(ng_dict[i]) - 1, end=" ")

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

n, m, k = map(int, input().split())

class UnionFind:
    def __init__(self, n):
        self.p = [-1]*n
        self.c = None

    def find(self, x):
        if self.p[x] < 0:
            return x
        else:
            self.p[x] = self.find(self.p[x])
            return self.p[x]

    def union(self, x, y):
        rx, ry = self.find(x), self.find(y)
        if rx != ry:
            self.p[ry] += self.p[rx]
            self.p[rx] = ry

    def count_member(self, x):
        return -self.p[self.find(x)]


uf = UnionFind(n)

ab = []
for i in range(m):
    a, b = map(lambda x: int(x)-1, input().split())
    ab.append((a, b))
    uf.union(a, b)

cd = [list(map(lambda x: int(x)-1, input().split())) for _ in range(k)]
ans = [uf.count_member(i)-1 for i in range(n)]

for a, b in ab:
    if uf.find(a) == uf.find(b):
        ans[a] -= 1
        ans[b] -= 1

for c, d in cd:
    if uf.find(c) == uf.find(d):
        ans[c] -= 1
        ans[d] -= 1

print(*ans)

Solution (Python):

n,m,k = map(int,input().split())

ab = [ list(map(int,input().split())) for _ in range(m) ]
cd = [ list(map(int,input().split())) for _ in range(k) ]




class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

uf = UnionFind(n)

ls_friend = [0]*n
for i in range(m):
    ls_friend[ ab[i][0]-1 ] += 1
    ls_friend[ ab[i][1]-1 ] += 1
    uf.union( ab[i][0]-1, ab[i][1]-1 )

ls_block = [0]*n
for i in range(k):
    if uf.same( cd[i][0]-1, cd[i][1]-1 ):
        ls_block[ cd[i][0]-1 ] += 1
        ls_block[ cd[i][1]-1 ] += 1
    else:
        pass



ls_ans = [0]*n
for i in range(n):
    ls_ans[i] += uf.size(i) - 1 - ls_friend[i] - ls_block[i]

print(" ".join(list(map(str,ls_ans))))

Solution (Python):
n, m, k = map(int, input().split())

friends = [[] for _ in range(n+1)]
blocks = [[] for _ in range(n+1)]

for _ in range(m):
    a, b = map(int, input().split())
    friends[a].append(b)
    friends[b].append(a)

for _ in range(k):
    c, d = map(int, input().split())
    blocks[c].append(d)
    blocks[d].append(c)

groups = [-1]*(n+1)
n_groups = []
g = 0
for i in range(1, n+1):
    if groups[i]>=0:
        continue
    stack = [i]
    cnt = 0
    groups[i] = g
    while len(stack)>0:
        node = stack.pop()
        for c_node in friends[node]:
            if groups[c_node]>=0:
                continue
            stack.append(c_node)
            groups[c_node] = g
            cnt += 1
    n_groups.append(cnt)
    g += 1

ans = []
for i in range(1, n+1):
    tmp = n_groups[groups[i]]
    for j in friends[i]:
        if groups[i] == groups[j]:
            tmp -= 1
    for j in blocks[i]:
        if groups[i] == groups[j]:
            tmp -= 1
    ans.append(tmp)

print(*ans)