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):
import sys
import math
from collections import deque
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())
    """
    
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)))
    """

def main():
    n, m, k = list(map(int,sys.stdin.readline().split()))
    uf = UnionFind(n)
    num_of_friends = [-1] * n

    for _ in range(m):
        a, b = list(map(int,sys.stdin.readline().split()))
        a -= 1
        b -= 1
        uf.union(a,b)
        num_of_friends[a] -= 1
        num_of_friends[b] -= 1
        
    
    """
    for i2 in range(n):
        roots[find(i2)] += 1
        print(roots)"""
    for i3 in range(n):
        num_of_friends[i3] += uf.size(i3)
        

    for _ in range(k):
        c, d = list(map(int,sys.stdin.readline().split()))
        c -= 1
        d -= 1
        """
        if find(c) == find(d):
            num_of_friends[c] -= 1
            num_of_friends[d] -= 1
        """
        if uf.same(c,d):
            num_of_friends[c] -= 1
            num_of_friends[d] -= 1    
    
    print(' '.join([str(number) for number in num_of_friends]))

if __name__ == "__main__":
    main()

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)

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


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

U=UnionFind(n)

for a,b in AB:
	U.union(a-1,b-1)
	
res=[0]*n
for i in range(n):
	res[i]=U.size(i)-1
for a,b in AB:
	res[a-1]-=1
	res[b-1]-=1
for c,d in CD:
	if U.same(c-1,d-1):
		res[c-1]-=1
		res[d-1]-=1

print(*res)

Solution (Python):
import sys
input = sys.stdin.buffer.readline
from collections import defaultdict
def main():
    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 members(x):
        root = find(x)
        return [i for i in range(n) if find(i) == root]

    n, m, k = map(int, input().split())
    num_of_friends = [-1] * n
    par = [-1] * n
    for _ in range(m):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        unite(a, b)
        num_of_friends[a] += -1
        num_of_friends[b] += -1
    roots = defaultdict(int)
    
    for i2 in range(n):
        roots[find(i2)] += 1
    for i3 in range(n):
        
        num_of_friends[i3] += roots[find(i3)]
    for _ in range(k):
        c, d = map(int, input().split())
        c -= 1
        d -= 1
        if find(c) == find(d):
            num_of_friends[c] -= 1
            num_of_friends[d] -= 1

    for i in range(n):
        print(num_of_friends[i], end=' ')

if __name__ == '__main__':
    main()

Solution (Python):
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))

def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
def S(): return sys.stdin.readline().rstrip()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)

MOD = 998244353
INF = float("inf")
sys.setrecursionlimit(10**6+10)
input = sys.stdin.readline

import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))

def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
def S(): return sys.stdin.readline().rstrip()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)

MOD = 998244353
INF = float("inf")
sys.setrecursionlimit(10**6+10)
input = sys.stdin.readline

N,M,K = MI()
F = [[] for _ in range(N+1)]
B = [[] for _ in range(N+1)]
for i in range(M):
    a,b = MI()
    F[a].append(b)
    F[b].append(a)
for i in range(K):
    c,d = MI()
    B[c].append(d)
    B[d].append(c)
D = {}
visited = [False for _ in range(N+1)]
parent = [0 for _ in range(N+1)]

def dfs(i,root):
    if visited[i]:
        pass
    else:
        visited[i]=True
        parent[i] = root
        for next in F[i]:
            if visited[next]:
                continue
            D[root].add(next)
            dfs(next,root)


for root in range(1,N+1):
    if visited[root]:
        continue
    D[root]=set([root])
    dfs(root,root)
ans = [0]*N
for iam in range(1,N+1):
    temp_ans = len(D[parent[iam]])-len(F[iam])-1
    for block in B[iam]:
        if block in D[parent[iam]]:
            temp_ans -= 1
    ans[iam-1] = temp_ans

print(*ans)

Solution (Python):
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))

def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
def S(): return sys.stdin.readline().rstrip()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)

MOD = 998244353
INF = float("inf")
sys.setrecursionlimit(10**6+10)
input = sys.stdin.readline

import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))

def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
def S(): return sys.stdin.readline().rstrip()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)

MOD = 998244353
INF = float("inf")
sys.setrecursionlimit(10**6+10)
input = sys.stdin.readline

N,M,K = MI()
F = [[] for _ in range(N+1)]
B = [[] for _ in range(N+1)]
for i in range(M):
    a,b = MI()
    F[a].append(b)
    F[b].append(a)
for i in range(K):
    c,d = MI()
    B[c].append(d)
    B[d].append(c)
D = {}
visited = [False for _ in range(N+1)]
parent = [0 for _ in range(N+1)]

def dfs(i,root):
    if visited[i]:
        pass
    else:
        visited[i]=True
        parent[i] = root
        for next in F[i]:
            if visited[next]:
                continue
            D[root].add(next)
            dfs(next,root)


for root in range(1,N+1):
    if visited[root]:
        continue
    D[root]=set([root])
    dfs(root,root)
ans = [0]*N
for iam in range(1,N+1):
    temp_ans = len(D[parent[iam]])-len(F[iam])-1
    for block in B[iam]:
        if block in D[parent[iam]]:
            temp_ans -= 1
    ans[iam-1] = temp_ans

print(*ans)

Solution (Python):
import sys
input = sys.stdin.readline

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


def union(x, y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return

    
    if par[x] > par[y]:
        x, y = y, x
    
    par[x] += par[y]
    par[y] = x


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
friend = [0] * n
for _ in range(m):
    a, b = map(int, input().split())
    union(a-1, b-1)
    friend[a-1] += 1
    friend[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 = size(i) - friend[i] - 1
    for j in block[i]:
        if same(i, j):
            ans -= 1
    print(ans, end=' ')

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


def union(x, y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return

    
    if par[x] > par[y]:
        x, y = y, x
    par[x] += par[y]
    par[y] = x


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
friend = [0] * n
for _ in range(m):
    a, b = map(int, input().split())
    union(a-1, b-1)
    friend[a-1] += 1
    friend[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 = size(i) - friend[i] - 1
    for j in block[i]:
        if same(i, j):
            ans -= 1
    print(ans, end=' ')

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

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

par = [-1] * n
friend = [0] * n

for _ in range(m):
    a, b = map(int, input().split())
    unite(a-1, b-1)
    friend[a-1] += 1
    friend[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 = size(i) - friend[i] - 1
    for j in block[i]:
        if same(i, j):
            ans -= 1
    print(ans, end=' ')

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)

    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 main():

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

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

    ans_l = []
    for i in range(n):
        all_cnt = uf.size(i)
        ans = all_cnt - 1 - len(no_cnt_list[i])
        ans_l.append(ans)

    print(*ans_l)


if __name__ == "__main__":
    main()

Solution (Python):
from sys import setrecursionlimit
setrecursionlimit(2 * 10 ** 9)

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

f_G = [[] for _ in range(N)]
for a, b in AB:
  a, b = a-1, b-1
  f_G[a].append(b)
  f_G[b].append(a)

b_G = [[] for _ in range(N)]
for c, d in CD:
  c, d = c-1, d-1
  b_G[c].append(d)
  b_G[d].append(c)

def dfs(v):
  if visited[v]:
    return
  visited[v] = True
  for nv in f_G[v]:
    s.add(nv)
    dfs(nv)  

ans = [0] * N
visited = [False] * N

for i in range(N):
  if not visited[i]:
    s = set()
    dfs(i)
    l = len(s)
    for u in s:
      ans[u] = l - 1
      ans[u] -= len(set(f_G[u]) & s)
      ans[u] -= len(set(b_G[u]) & s)

print(*ans)

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]

from collections import defaultdict, deque
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left

import sys


mod = 10 ** 9 + 7

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 same(self, x, y):
        return self.find(x) == self.find(y)

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

N, M, K = getNM()


U = UnionFind(N)

friendlist = [getList() for i in range(M)]
blockedlist = [getList() for i in range(K)]

for a, b in friendlist:
    U.union(a - 1, b - 1)

friends = [0] * (N + 1)
blocks = [0] * (N + 1)


for a, b in friendlist:
    if U.same(a - 1, b - 1):
        friends[a - 1] += 1
        friends[b - 1] += 1
for a, b in blockedlist:
    if U.same(a - 1, b - 1):
        blocks[a - 1] += 1
        blocks[b - 1] += 1

ans = []
for i in range(N):
    
    cnt = U.size(i) - friends[i] - blocks[i] - 1
    ans.append(cnt)
print(*ans)

Solution (Python):
from sys import setrecursionlimit 
setrecursionlimit(10**6)

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

fr = [set() for _ in range(n)]
bl = [set() for _ in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    fr[a-1].add(b-1)
    fr[b-1].add(a-1)
    
for i in range(k):
    c ,d = map(int, input().split())
    bl[c-1].add(d-1)
    bl[d-1].add(c-1)
    
def dfs(v, temp):
    visited[v] = True
    temp.add(v)
    for i in fr[v]:
        if visited[i] == False:
            temp = dfs(i, temp)
    return temp
visited = [False]*n

cc = [0]*n
for v in range(n):
    if visited[v] == False:
        c = dfs(v,set())
        for i in c:
            cc[i] = c


ans = []
for i in range(n):
    aa = len(cc[i]) - len(cc[i] & fr[i]) - len(cc[i] & bl[i]) - 1
    ans.append(aa)
print(*ans)

Solution (Python):
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


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

    
    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:
            return
        
        if self.rank[x] > self.rank[y]:
            self.parent[y] = x
            self.size[x] += self.size[y]
        else:
            self.parent[x] = y
            self.size[y] += self.size[x]
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

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

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

    
    def get_parent_list(self):
        return [i for i in range(self.n_nodes) if self.find(i) == i]

    
    def get_n_groups(self):
        return len(self.get_parent_list())

    
    def get_members(self, x):
        parent = self.find(x)
        return [i for i in range(self.n_nodes) if self.find(i) == parent]

    
    def get_members_dict(self):
        return {par: self.get_members(par) for par in self.get_parent_list()}


MOD = 10 ** 9 + 7


def main():
    N, M, K = map(int, input().split())
    UF = UnionFind(N)
    friend = [0] * N
    block = [0] * N
    for _ in range(M):
        a, b = map(int, input().split())
        UF.unite(a - 1, b - 1)
        friend[a - 1] += 1
        friend[b - 1] += 1

    for _ in range(K):
        c, d = map(int, input().split())
        if UF.check(c - 1, d - 1):
            block[c - 1] += 1
            block[d - 1] += 1
    answer = []
    for i in range(N):
        answer.append(UF.get_size(i) - friend[i] - block[i] - 1)
    print(*answer, sep=" ")


if __name__ == "__main__":
    main()

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

    def find(self, x):
        """要素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が属するグループと要素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):
        """要素xが属するグループの要素数を返す"""
        return -self.parents[self.find(x)]

    def same(self, x, y):
        """要素x, yが同じグループに属するかどうかを返す"""
        return self.find(x) == self.find(y)

    def members(self, x):
        """要素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 main():
    N, M, K = map(int, input().split())
    cnt = [0] * N
    uf = UnionFind(N)

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

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

    for i in range(N):
        print(uf.size(i) - cnt[i] - 1, end=" ")


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9+7
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())


n,m,k = map(int,input().split())
fb = [0]*n
uf = UnionFind(n)
for i in range(m):
    a,b = map(int,input().split())
    uf.union(a-1,b-1)
    fb[a-1] += 1
    fb[b-1] += 1
for i in range(k):
    c,d = map(int,input().split())
    if uf.same(c-1,d-1):
        fb[c-1] += 1
        fb[d-1] += 1
Ans = []
for i in range(n):
    ans = uf.size(i) - fb[i] - 1
    Ans.append(ans)
print(*Ans)

Solution (Python):
from sys import stdin, setrecursionlimit


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

    def find(self, x):
        p = self.parent
        while p[x] >= 0:
            x, p[x] = p[x], p[p[x]]
        return x

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

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

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


def main():
    input = stdin.buffer.readline
    n, m, k = map(int, input().split())

    f = UnionFindTree(n)

    f_or_b = [0] * n

    for _ in range(m):
        a, b = map(int, input().split())
        f.union(a - 1, b - 1)
        f_or_b[a - 1] += 1
        f_or_b[b - 1] += 1

    for _ in range(k):
        c, d = map(int, input().split())
        if f.same(c - 1, d - 1):
            f_or_b[c - 1] += 1
            f_or_b[d - 1] += 1

    print(*[f.size(i) - f_or_b[i] - 1 for i in range(n)])


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Solution (Python):
from sys import stdin, setrecursionlimit


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

    def find(self, x):
        p = self.parent
        while p[x] >= 0:
            x, p[x] = p[x], p[p[x]]
        return x

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

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

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


def main():
    n, m, k = map(int, stdin.readline().split())

    f = UnionFindTree(n)

    f_or_b = [0] * n

    for _ in range(m):
        a, b = map(int, stdin.readline().split())
        f.union(a - 1, b - 1)
        f_or_b[a - 1] += 1
        f_or_b[b - 1] += 1

    for _ in range(k):
        c, d = map(int, stdin.readline().split())
        if f.same(c - 1, d - 1):
            f_or_b[c - 1] += 1
            f_or_b[d - 1] += 1

    print(*[f.size(i) - f_or_b[i] - 1 for i in range(n)])


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Solution (Python):
from sys import stdin, setrecursionlimit


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

    def find(self, x):
        p = self.parent
        while p[x] >= 0:
            x, p[x] = p[x], p[p[x]]
        return x

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

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

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


def main():
    n, m, k = map(int, stdin.readline().split())

    f = UnionFindTree(n)

    f_or_b = [0] * n

    for _ in range(m):
        a, b = map(int, stdin.readline().split())
        f.union(a - 1, b - 1)
        f_or_b[a - 1] += 1
        f_or_b[b - 1] += 1

    for _ in range(k):
        c, d = map(int, stdin.readline().split())
        if f.same(c - 1, d - 1):
            f_or_b[c - 1] += 1
            f_or_b[d - 1] += 1

    print(*[f.size(i) - f_or_b[i] - 1 for i in range(n)])


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Solution (Python):
import collections
import sys
n,m,k = map(int,sys.stdin.readline().split())
parent = range(n+1)
sizes = [1] * (n + 1)
hd = [1] * (n + 1) 

def f(parent, u):
	if parent[u] != u:  parent[u] = f(parent, parent[u])
	return parent[u]

while(m):
	m-=1
	a,b = map(int,sys.stdin.readline().split())
	pa,pb = f(parent, a), f(parent, b)
	hd[a] +=1
	hd[b] +=1

	if pa != pb:
		if sizes[pa] <= sizes[pb]: pa,pb = pb,pa
		parent[pb] = pa
		sizes[pa] += sizes[pb]
		
while(k):
	k-=1
	a,b= map(int,sys.stdin.readline().split())
	pa,pb = f(parent, a), f(parent,b)
	if (pa == pb):
		hd[a] += 1
		hd[b] += 1
for u in range(1,n+1):
	print str(sizes[f(parent,u)] - hd[u]) ,