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.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)

import sys
input = sys.stdin.readline
N,M,K = map(int,input().split())
uf = UnionFind(N)
lst=[0]*(N)
ans=[0]*(N)
for i in [0]*M:
 A,B=map(int,input().split())
 uf.union(A-1,B-1)
 lst[A-1]+=1
 lst[B-1]+=1
for i in [0]*K:
 A,B=map(int,input().split())
 if uf.same(A-1,B-1):
  lst[A-1]+=1
  lst[B-1]+=1
for i in range(N):
 ans[i]=uf.size(i)-lst[i]-1
L=[str(a) for a in ans]
L=' '.join(L)
print(L)

Solution (Python):
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)
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)

import sys
input = sys.stdin.readline
N,M,K = map(int,input().split())
uf = UnionFind(N)
lst=[0]*(N)
ans=[0]*(N)
for i in range(M):
 A,B=map(int,input().split())
 uf.union(A-1,B-1)
 lst[A-1]+=1
 lst[B-1]+=1
for i in range(K):
 A,B=map(int,input().split())
 if uf.same(A-1,B-1):
  lst[A-1]+=1
  lst[B-1]+=1
for i in range(N):
 ans[i]=uf.size(i)-lst[i]-1
L=[str(a) for a in ans]
L=' '.join(L)
print(L)

Solution (Python):
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)

N,M,K = map(int,input().split())
uf = UnionFind(N)
lst=[0]*(N)
ans=[0]*(N)
for i in range(M):
 A,B=map(int,input().split())
 uf.union(A-1,B-1)
 lst[A-1]+=1
 lst[B-1]+=1
for i in range(K):
 A,B=map(int,input().split())
 if uf.same(A-1,B-1):
  lst[A-1]+=1
  lst[B-1]+=1
for i in range(N):
 ans[i]=uf.size(i)-lst[i]-1
L=[str(a) for a in ans]
L=' '.join(L)
print(L)

Solution (Python):
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)

N,M,K = map(int,input().split())
uf = UnionFind(N)
lst=[0]*(N)
ans=[0]*(N)
for i in range(M):
 A,B=map(int,input().split())
 uf.union(A-1,B-1)
 lst[A-1]+=1
 lst[B-1]+=1
for i in range(K):
 A,B=map(int,input().split())
 if uf.same(A-1,B-1):
  lst[A-1]+=1
  lst[B-1]+=1
for i in range(N):
 ans[i]=uf.size(i)-lst[i]-1
L=[str(a) for a in ans]
L=' '.join(L)
print(L)

Solution (Python):
from collections import defaultdict

N, M, K = map(int, input().split())
friends = defaultdict(list)
blocked = defaultdict(list)
for i in range(M):
    a, b = map(int, input().split())
    friends[a - 1].append(b - 1)
    friends[b - 1].append(a - 1)
for j in range(K):
    c, d = map(int, input().split())
    blocked[c - 1].append(d - 1)
    blocked[d - 1].append(c - 1)

groups = {}
for i in range(N):
    if i in groups:
        continue
    group = {i}
    stack = [(i, None)]
    while stack:
        j, parent_id = stack.pop()
        group.add(j)
        groups[j] = group
        for k in friends[j]:
            if k != parent_id and k not in groups:
                stack.append((k, j))

ans = []
for i in range(N):
    g = groups[i]
    res = len(g) - len(friends[i]) - 1
    for b in blocked[i]:
        if groups[b] is g:
            res -= 1
    ans.append(res)
print(*ans)

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

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

    def Unite(self,x,y):
        x=self.Find_Root(x)
        y=self.Find_Root(y)

        if x==y:return
        elif self.rank[x]>self.rank[y]:
            self.root[x] +=self.root[y]
            self.root[y]=x
        else:
            self.root[y] +=self.root[x]
            self.root[x]=y
            if self.rank[x]==self.rank[y]:
                self.rank[y] +=1

    def isSameGroup(self,x,y):
        return self.Find_Root(x)==self.Find_Root(y)

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

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

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

    def group_members(self):
        return {i:self.members(i) for i in self.roots()}

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


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)]

UnionFind=UnionFind(n+1)
Friend=[0 for _ in range(n+1)]
for a,b in AB:
    Friend[a] +=1
    Friend[b] +=1
    UnionFind.Unite(a,b)
Block=[0 for _ in range(n+1)]
for c,d in CD:
    if UnionFind.isSameGroup(c,d):
        Block[c] +=1
        Block[d] +=1

A=[]
for i in range(1,n+1):
    A.append(UnionFind.size(i)-Friend[i]-Block[i]-1)
print(*A)

Solution (Python):
class UnionFind:

    def __init__(self, n):
        self.parents = [i for i in range(n)]
        self.ranks = [0 for _ in range(n)]
        self.sizes = [1 for _ in range(n)]

    def find_root(self, node):
        parent_node = self.parents[node]
        if parent_node == node:
            return node
        else:
            root_node = self.find_root(parent_node)
            self.parents[node] = root_node  
            return root_node

    def is_same_group(self, one_node, other_node):
        one_root = self.find_root(one_node)
        other_root = self.find_root(other_node)
        return one_root == other_root

    def union(self, one_node, other_node):
        one_root = self.find_root(one_node)
        other_root = self.find_root(other_node)
        if one_root == other_root:
            return
        one_rank = self.ranks[one_root]
        other_rank = self.ranks[other_root]
        if one_rank < other_rank:
            self.parents[one_root] = other_root
            self.sizes[other_root] += self.sizes[one_root]
        else:
            self.parents[other_root] = one_root
            self.sizes[one_root] += self.sizes[other_root]
            if one_rank == other_rank:
                self.ranks[one_root] += 1

    def group_size(self, node):
        root_node = self.find_root(node)
        return self.sizes[root_node]


def main():
    N, M, K = list(map(int, input().split(' ')))
    non_suggested_users = [[] for _ in range(N)]
    friend_tree = UnionFind(N)
    for _ in range(M):
        a, b = list(map(int, input().split(' ')))
        one_user = a - 1
        other_user = b - 1
        friend_tree.union(one_user, other_user)
        non_suggested_users[one_user].append(other_user)
        non_suggested_users[other_user].append(one_user)
    for _ in range(K):
        c, d = list(map(int, input().split(' ')))
        one_user = c - 1
        other_user = d - 1
        if friend_tree.is_same_group(one_user, other_user):
            non_suggested_users[one_user].append(other_user)
            non_suggested_users[other_user].append(one_user)
    answer_list = list()
    for user in range(N):
        ans = friend_tree.group_size(user) - len(non_suggested_users[user]) - 1
        answer_list.append(str(ans))
    print(' '.join(answer_list))


if __name__ == '__main__':
    main()

Solution (Python):


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)]
 
N,M,K = map(int,input().split())


par = [-1]*(N+1)
 
friends = [[]for i in range(0,N+1,1)]
block = [[]for i in range(0,N+1,1)]
for i in range(0,M,1):
    a,b = map(int,input().split())
    friends[a].append(b)
    friends[b].append(a)
    unite(a,b)
for i in range(0,K,1):
    a,b=map(int,input().split())
    block[a].append(b)
    block[b].append(a)
 
countmem = [0]*N
for i in range(1,N+1,1):
    count = size(i)-1
    mem = []
    ma = mem.append
    for j in range(0,len(friends[i]),1):
        if same(i,friends[i][j]):
            count -=1
            ma(friends[i][j])
    for j in range(0,len(block[i]),1):
        if same(i,block[i][j]) and not(block[i][j] in mem):
            count -=1
    countmem[i-1]=count
 
print(*countmem)

Solution (Python):


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)]

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


par = [-1]*(N+1)

friends = [[]for i in range(0,N+1,1)]
block = [[]for i in range(0,N+1,1)]
for i in range(0,M,1):
    a,b = map(int,input().split())
    friends[a].append(b)
    friends[b].append(a)
    unite(a,b)
for i in range(0,K,1):
    a,b=map(int,input().split())
    block[a].append(b)
    block[b].append(a)

for i in range(1,N+1,1):
    friends[i].extend(block[i])
    set(friends[i])

countmem = [0]*N
for i in range(1,N+1,1):
    count = size(i)-1
    for j in range(0,len(friends[i]),1):
        if same(i,friends[i][j]):
            count -=1
    countmem[i-1]=count

print(*countmem)

Solution (Python):
class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0] * n
        self.siz = [1] * 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 union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                self.par[x] = y
                self.siz[y] += self.siz[x]
            else:
                self.par[y] = x
                self.siz[x] += self.siz[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 size(self, x):
        return self.siz[self.find(x)]

    def print_tree(self):
        print(self.rank)
        print(self.par)

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

uf = UnionFind(n)
ng = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a-=1
    b-=1
    uf.union(a, b)

    ng[a].append(b)
    ng[b].append(a)

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

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

print(*ans)

Solution (Python):
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)]


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.unite(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.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
print(*ans)

Solution (Python):
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)

UFT = UnionFind(N)
ans = [0 for _ in range(N)]

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

for _ in range(K):
    C, D = map(int,input().split())
    if UFT.same(C-1, D-1):
        ans[C-1] -= 1
        ans[D-1] -= 1

ans = [UFT.size(i) + ans[i] - 1 for i in range(N)]

print(*ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**5)

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * n 
        self.size = [1] * 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 same(self, x, y):
        return self.find(x) == self.find(y)
    
    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.par[x] = y
            self.size[y] = self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1
                
n, m, k = map(int, input().split())
friends = [[] for _ in range(n)]
blocks = [[] for _ in range(n)]

for i in range(m):
    x, y = map(lambda x: int(x) - 1, input().split())
    friends[x].append(y)
    friends[y].append(x)

for i in range(k):
    x, y = map(lambda x: int(x) - 1, input().split())
    blocks[x].append(y)
    blocks[y].append(x)

uf = UnionFind(n)
for i in range(n):
    for f in friends[i]:
        uf.union(i, f)


ans = [uf.size[uf.find(i)] - 1 for i in range(n)]

for i in range(n):
    ans[i] -= len(friends[i])

for i in range(n):
    for b in blocks[i]:
        if uf.same(i, b):
            ans[i] -= 1

print(*ans)

Solution (Python):


from collections import defaultdict
n, m, k = list(map(int, input().split()))
ns = defaultdict(set)
bs = defaultdict(set)
for i in range(m):
    a,b = list(map(int, input().split()))
    ns[a-1].add(b-1)
    ns[b-1].add(a-1)
for i in range(k):
    c,d = list(map(int, input().split()))
    bs[c-1].add(d-1)
    bs[d-1].add(c-1)
    
s = [0]
start = 0
parent = [None] * n
starts = defaultdict(int)
starts[0] = 0
notdone = set(list(range(n)))
notdone.remove(start)
while notdone or s:
    u = s.pop()
    parent[u] = start
    starts[start] += 1
    for v in ns[u]:
        if v in notdone:
            s.append(v)
            notdone.remove(v)
    if not s and notdone:
        start = notdone.pop()
        parent[start] = start
        s.append(start)
ans = [None] * n
for u in range(n):
    val = starts[parent[u]] - 1 - len(ns[u])
    for v in bs[u]:
        if parent[v]==parent[u]:
            val -= 1
    ans[u] = val
print(" ".join(map(str, ans)))

Solution (Python):


from collections import defaultdict
n, m, k = list(map(int, input().split()))
ns = defaultdict(set)
bs = defaultdict(set)
for i in range(m):
    a,b = list(map(int, input().split()))
    ns[a-1].add(b-1)
    ns[b-1].add(a-1)
for i in range(k):
    c,d = list(map(int, input().split()))
    bs[c-1].add(d-1)
    bs[d-1].add(c-1)
    
s = [0]
start = 0
parent = [None] * n
starts = defaultdict(int)
starts[0] = 0
notdone = set(list(range(n)))
notdone.remove(start)
while notdone or s:
    u = s.pop()
    parent[u] = start
    starts[start] += 1
    for v in ns[u]:
        if v in notdone:
            s.append(v)
            notdone.remove(v)
    if not s and notdone:
        start = notdone.pop()
        parent[start] = start
        s.append(start)
ans = [None] * n
for u in range(n):
    val = starts[parent[u]] - 1 - len(ns[u])
    for v in bs[u]:
        if parent[v]==parent[u]:
            val -= 1
    ans[u] = val
print(" ".join(map(str, ans)))

Solution (Python):
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)


N, M, K = map(int, input().split(" "))
uf = UnionFind(N)
deg = [1 for i in range(N)]
same = [0 for i in range(N)]

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

for _ in range(K):
    C, D = map(int, input().split(" "))
    if uf.same(C - 1, D - 1):
        same[C - 1] += 1
        same[D - 1] += 1


ans = [uf.size(i) - deg[i] - same[i] for i in range(N)]
print(' '.join([str(a) for a in ans]))

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
def main():
    class unionfind():
        def __init__(self,n):
            self.par = [i for i in range(n)]
            self.size = [1 for i in range(n)]
            self.rank = [0 for i in range(n)]
 
        def root(self,x):
            if self.par[x] == x:
                return x
            else:
                self.par[x] = self.root(self.par[x])
                return self.par[x]
 
        def same(self,x,y):
            return self.root(x) == self.root(y)
 
        def unite(self,x,y):
            x = self.root(x)
            y = self.root(y)
            if x==y:return
            else:
                if self.rank[x] < self.rank[y]:
                     x,y = y,x
                if self.rank[x] == self.rank[y]:
                    self.rank[x]+=1
                self.par[y] = x
                self.size[x] +=self.size[y]
        def get_size(self,x):
            x = self.root(x)
            return self.size[x]
 
    
    input = sys.stdin.readline
    n,m,k = map(int,input().split())
    uff = unionfind(n)
    fr = [0 for i in range(n)]
 
 
    for i in range(m):
        a,b = map(int,input().split())
        uff.unite(a-1,b-1)
        fr[a-1]+=1
        fr[b-1]+=1
 
 
    ans = [uff.get_size(i) -fr[i]-1 for i in range(n)]
 
    for i in range(k):
        c,d = map(int,input().split())
        if uff.same(c-1,d-1):
            ans[c-1] -=1
            ans[d-1] -=1
    print(*ans)
if __name__=="__main__":
    main()

Solution (Python):
def main():
    class unionfind():
        def __init__(self,n):
            self.par = [i for i in range(n)]
            self.size = [1 for i in range(n)]
            self.rank = [0 for i in range(n)]
 
        def root(self,x):
            if self.par[x] == x:
                return x
            else:
                self.par[x] = self.root(self.par[x])
                return self.par[x]
 
        def same(self,x,y):
            return self.root(x) == self.root(y)
 
        def unite(self,x,y):
            x = self.root(x)
            y = self.root(y)
            if x==y:return
            else:
                if self.rank[x] < self.rank[y]:
                     x,y = y,x
                if self.rank[x] < self.rank[y]:
                    self.rank[x]+=1
                self.par[y] = x
                self.size[x] +=self.size[y]
        def get_size(self,x):
            x = self.root(x)
            return self.size[x]
 
    import sys
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    n,m,k = map(int,input().split())
    uff = unionfind(n)
    fr = [0 for i in range(n)]
 
 
    for i in range(m):
        a,b = map(int,input().split())
        uff.unite(a-1,b-1)
        fr[a-1]+=1
        fr[b-1]+=1
 
 
    ans = [uff.get_size(i) -fr[i]-1 for i in range(n)]
 
    for i in range(k):
        c,d = map(int,input().split())
        if uff.same(c-1,d-1):
            ans[c-1] -=1
            ans[d-1] -=1
    print(*ans)
if __name__=="__main__":
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10**7)

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


par=[index for index in range(N+1)]

def root(x):
    global par

    if x==par[x]:
        return x
    else:
        par[x]=root(par[x])
        return par[x]


def same(x,y):
    global par

    if root(x)==root(y):
        return True
    else:
        return False

def unite(x,y):
    global par

    if root(x)!=root(y):
        par[root(x)]=root(y)


friends=[[] for index1 in range(N+1)]
for index2 in range(M):
    a,b=map(int,input().split())
    unite(a,b)
    friends[a].append(b)
    friends[b].append(a)


block=[[] for index3 in range(N+1)]
for index4 in range(K):
    c,d=map(int,input().split())
    block[c].append(d)
    block[d].append(c)


relates=[0]*(N+1)
for i in range(1,N+1):
    relates[root(i)]+=1


Ans=[]
for j in range(1,N+1):
    ans=relates[root(j)]-1    
    for k in friends[j]:
        if same(j,k):
            ans-=1
    for l in block[j]:
        if same(j,l):   
            ans-=1

    Ans.append(ans)

print(*Ans)

Solution (Python):
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 members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def same( self, x, y ):
      return self.find( x ) == self.find( y )

uf = UnionFind( N + 1 )
not_use = [ 0 ] * ( N + 1 )
for i in range( M ):
  a, b = map( int, input().split() )
  uf.union( a, b )
  not_use[ a ] += 1
  not_use[ b ] += 1

block = [ [] for _ in range( N + 1 ) ]
for i in range( K ):
  c, d = map( int, input().split() )
  if uf.same( c, d ):
    not_use[ c ] += 1
    not_use[ d ] += 1

ans = str( uf.size( 1 ) - not_use[ 1 ] - 1 )
for i in range( 2, N + 1 ):
  ans += " " + str( uf.size( i ) - not_use[ i ] - 1 )
print( ans )

Solution (Python):
import sys
sys.setrecursionlimit(4100000)

from collections import Counter

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

to = [[] for i in range(N)]
block = [[] for i in range(N)]
sets = []

is_visited = [False] * N
graph_g = [None] * N
graph_cnt = -1

def dfs(s, g):
    global graph_cnt
    if is_visited[s]:
        return 0

    is_visited[s] = True
    if g == None:
        graph_cnt += 1
        graph_g[s] = graph_cnt
    else:
        graph_g[s] = g

    for edge in to[s]:
        if graph_g[edge] == None:
            dfs(edge, graph_cnt)


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

for i in range(N):
    if is_visited[i]:
        continue
    dfs(i, None)

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

ct = Counter(graph_g)

ret = []
for i in range(N):
    cand = ct[graph_g[i]]
    fri = len(to[i])
    tmp_block = len(block[i])

    tmp_ret = cand - fri - tmp_block - 1
    ret.append(tmp_ret)

print(*ret)

Solution (Python):

import sys
sysread = sys.stdin.readline
from collections import defaultdict
sys.setrecursionlimit(10**7)
def run():

    N,M,K = map(int,sysread().split())
    to = [[] for _ in range(N+1)]
    n_to = [0 for _ in range(N + 1)]
    for i in range(1,M+1):
        a,b = map(int, sysread().split())
        
        to[a].append(b)
        n_to[a] += 1
        to[b].append(a)
        n_to[b] += 1

    stack = defaultdict(lambda:0)
    visited = [False] * (N+1)
    belong = [None] * (N+1)


    def dfs(n):
        _stack = [n]
        visited[n] = True
        while _stack:
            node = _stack.pop()
            stack[n] += 1
            belong[node] = n
            for next in to[node]:
                if not visited[next]:
                    _stack.append(next)
                    visited[next] = True
        return None


    for i in range(1,N+1):
        if not visited[i]:
            dfs(i)

    block = [0 for _ in range(N+1)]
    for i in range(1, K+1):
        c,d = map(int, sysread().split())
        
        if belong[c] == belong[d]:
            block[c] += 1
            block[d] += 1

    candidates = [0] * (N+1)

    for k in range(1,N+1):
        tr = belong[k]
        candidates[k] = stack[tr] - 1 - n_to[k] - block[k]

    print(' '.join(map(str, candidates[1:])))

if __name__ == "__main__":
    run()