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):
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
ceil = math.ceil

class unionfind():
    def __init__(self,n):
        self.par = list(range(n))
        self.size = [1]*n
        self.rank = [0]*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]
    def parent_set(self):
        s = set()
        for par in self.par:
            s.add(par)
        return s
n,m,k = map(int,input().split())
uf = unionfind(n)
fr = [0 for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    uf.unite(a-1,b-1)
    fr[a-1]+=1
    fr[b-1]+=1
ans = [uf.get_size(i) -fr[i]-1 for i in range(n)]
for i in range(k):
    c,d = map(int,input().split())
    if uf.same(c-1,d-1):
        ans[c-1] -=1
        ans[d-1] -=1
print(*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)

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

uf = UnionFind(N+1)
AB_list = []

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

dame = [[] for i in range(N+1)]
for i in range(M):
    if uf.same(AB_list[i][0], AB_list[i][1]):
        dame[AB_list[i][0]].append(AB_list[i][1])
        dame[AB_list[i][1]].append(AB_list[i][0])

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

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

Solution (Python):
from collections import deque
import numpy as np

N, M, K = [int(x) for x in input().split()]

friends = [[] for _ in range(N + 1)]
for i in range(M):
    A, B = [int(x) for x in input().split()]
    friends[A].append(B)
    friends[B].append(A)

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

G = []
check = [False] * (N + 1)
for i in range(1, N + 1):
    if check[i] == False:
        check[i] = True
        g = [i]
        q = deque([i])
        while q:
            j = q.popleft()
            for k in friends[j]:
                if check[k] == False:
                    check[k] = True
                    g.append(k)
                    q.append(k)
        G.append(g)

gr = np.array([0] * (N + 1))
fr = np.array([len(friends[i]) for i in range(N + 1)])
bl = np.array([0] * (N + 1))

for g in G:
    s = set(g)
    for v in g:
        gr[v] = len(g)
        b = set(block[v])
        bl[v] = len(s & b)

ans = gr - fr - bl - np.array([1] * (N + 1))

for i in range(1, N + 1):
    print(ans[i], end='')
    if i == N:
        print('')
    else:
        print(' ', end='')

Solution (Python):
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import connected_components


class People:
    def __init__(self):
        self.frends = 0
        self.blocks = 0


n, m, k = [int(i) for i in input().split()]

data=[1]*m
row=[]
col=[]
peoples = [People() for i in range(n + 1)]
for i in range(m):
    one, two = [int(j) for j in input().split()]
    new_one=min(one,two)
    new_two=max(one,two)
    row.append(one)
    col.append(two)
    peoples[one].frends+=1
    peoples[two].frends+=1

frends = csr_matrix((data, (row, col)), shape=(n+1, n+1))


num, labels = connected_components(frends)
labels=list(labels)

for i in range(k):
    one, two = [int(j) for j in input().split()]
    if labels[one] == labels[two]:
        peoples[one].blocks+=1
        peoples[two].blocks+=1

renketu_num = [0]*num
for i in labels:
    renketu_num[i]+=1


def get_renketu_num(i):
    return renketu_num[labels[i]] - 1


def get_friend_num(i):
    return peoples[i].frends


def get_block_num(i):
    return peoples[i].blocks


for i in range(1, n + 1):
    print(get_renketu_num(i) - get_friend_num(i) - get_block_num(i))

Solution (Python):
from collections import deque
N, M, K = map(int, input().split())
A = [[] for i in range(N)]
B = [[] for i in range(N)]
for i in range(M):
  a, b = map(lambda x:int(x)-1, input().split())
  A[a].append(b)
  A[b].append(a)
for i in range(K):
  a, b = map(lambda x:int(x)-1, input().split())
  B[a].append(b)
  B[b].append(a)
P = [-1 for i in range(N)]
Q = []
k = -1
for i in range(N):
  if P[i] == -1:
    q = 1
    k += 1
    P[i] = k
    d = deque([i])
    while len(d):
      s = d.pop()
      for t in A[s]:
        if P[t] == -1:
          P[t] = k
          q += 1
          d.append(t)
    Q.append(q)
for i in range(N):
  ans = Q[P[i]] - len(A[i]) - 1
  for j in B[i]:
    if P[i] == P[j]:
      ans -= 1
  print(ans)

Solution (Python):
N, M, K = map(int, input().split())
ans = [0] * N
class unionfind():
  def __init__(self, N):
    self.__N = N
    self.__parent = [-1] * (N + 1)
    
  def table(self):
    print(self.__parent)
    
  def find_parent(self, x):
    if self.__parent[x] < 0:
      return x
    else:
      self.__parent[x] = self.find_parent(self.__parent[x])
      return self.__parent[x]
    
  def union(self, x, y):
    x = self.find_parent(x)
    y = self.find_parent(y)
    if x == y :
      return
    if self.__parent[x] > self.__parent[y]:
      x, y = y, x
    self.__parent[x] += self.__parent[y]
    self.__parent[y] = x
    
  def size(self, x):
    return  -self.__parent[self.find_parent(x)]
  
  def same(self, x, y):
    if self.find_parent(x) == self.find_parent(y):
      return True
    else:
      return False

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

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

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

Solution (Python):
n,m,k = map(int,input().split())
par = [-1]*(n+1)
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x]) 
        return par[x]
def same(x,y):
    return find(x) == find(y)
def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return 0
    else:
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
def size(x):
    return -par[find(x)]
g = [[] for _ in range(n+1)]
b = [[] for _ in range(n+1)]
for _ in range(m):
    s,t = map(int,input().split())
    unite(s,t)
    g[s].append(t)
    g[t].append(s)
for _ in range(k):
    s,t = map(int,input().split())
    b[s].append(t)
    b[t].append(s)
for i in range(1,n+1):
    ans = size(i)-1-len(g[i])
    for e in b[i]:
        if same(i,e):
            ans -= 1
    print(ans,end=" ")

Solution (Python):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy


import heapq
sys.setrecursionlimit(10**6)

INF = 10**18
import bisect
import statistics
mod = 10**9+7


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

al = [[] for i in range(N+1)]
for i in range(M):
    a, b = map(int, input().split())
    al[a].append(b)
    al[b].append(a)

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

seen = [0 for i in range(N+1)]
num_connect = [0 for i in range(N+1)]
cluster = [0 for i in range(N+1)]

def bfs(u, c):
    visited = []
    stack = deque([u])
    seen[u] = 1
    count = 1

    while len(stack) > 0:
        v = stack.popleft()
        visited.append(v)
        cluster[v] = c
        for w in al[v]:
            if seen[w] == 0:
                stack.append(w)
                count += 1
                seen[w] = 1

    for v in visited:
        num_connect[v] = count

c = 1
for i in range(1,N+1):
    if seen[i] == 0:
        bfs(i, c)
        c += 1

for i in range(1,N+1):
    bl = 0
    for d in block[i]:
        if cluster[i] == cluster[d]:
            bl += 1
    print(num_connect[i] - 1 - len(al[i]) - bl, end=" ")

Solution (Python):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy


import heapq
sys.setrecursionlimit(10**6)

INF = 10**18
import bisect
import statistics
mod = 10**9+7


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

al = [[] for i in range(N+1)]
for i in range(M):
    a, b = map(int, input().split())
    al[a].append(b)
    al[b].append(a)

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

seen = [0 for i in range(N+1)]
num_connect = [0 for i in range(N+1)]
cluster = [0 for i in range(N+1)]

def bfs(u, c):
    visited = []
    stack = deque([u])
    seen[u] = 1
    count = 1

    while len(stack) > 0:
        v = stack.popleft()
        visited.append(v)
        cluster[v] = c
        for w in al[v]:
            if seen[w] == 0:
                stack.append(w)
                count += 1
                seen[w] = 1

    for v in visited:
        num_connect[v] = count

c = 1
for i in range(1,N+1):
    if seen[i] == 0:
        bfs(i, c)
        c += 1

for i in range(1,N+1):
    bl = 0
    for d in block[i]:
        if cluster[i] == cluster[d]:
            bl += 1
    print(num_connect[i] - 1 - len(al[i]) - bl, end=" ")
print()

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())
ans = [-1 for _ in range(n)]
UF = UnionFind(n)
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    UF.union(a, b)
    ans[a] -= 1
    ans[b] -= 1
    
for i in range(n):
    ans[i] += UF.size(i)

for _ in range(k):
    c, d = map(int, input().split())
    c -= 1
    d -= 1
    if UF.same(c, d):
        ans[c] -= 1
        ans[d] -= 1
print(*ans)

Solution (Python):
class UnionFind():
    def __init__(self, n):
        self.n = n
        
        self.root = [-1]*(n)
        
        self.rank = [0]*(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 same(self, x, y):
        return self.find_root(x) == self.find_root(y)
    
    def count(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, x in enumerate(self.root) 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()}

N, M, K = map(int,input().rstrip().split())
AB=[list(map(int,input().rstrip().split()))for _ in range(M)]
CD=[list(map(int,input().rstrip().split()))for _ in range(K)]

u = UnionFind(N)
for a,b in AB:
    u.unite(a-1,b-1)

ans=[u.count(i)-1 for i in range(N)] 
ans

for a,b in AB:
    if u.same(a-1,b-1):
        ans[a-1]-=1
        ans[b-1]-=1

for c,d in CD:
    if u.same(c-1,d-1):
        ans[c-1]-=1
        ans[d-1]-=1
print(*ans)

Solution (Python):
class UnionFind():
    def __init__(self, n):
        self.n = n
        
        self.root = [-1]*(n)
        
        self.rank = [0]*(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 same(self, x, y):
        return self.find_root(x) == self.find_root(y)
    
    def count(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, x in enumerate(self.root) 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()}

N, M, K = map(int,input().rstrip().split())
AB=[list(map(int,input().rstrip().split()))for _ in range(M)]
CD=[list(map(int,input().rstrip().split()))for _ in range(K)]

u = UnionFind(N)
for a,b in AB:
    u.unite(a-1,b-1)

ans=[u.count(i)-1 for i in range(N)] 
ans

for a,b in AB:
    if u.same(a-1,b-1):
        ans[a-1]-=1
        ans[b-1]-=1

for c,d in CD:
    if u.same(c-1,d-1):
        ans[c-1]-=1
        ans[d-1]-=1
print(*ans)

Solution (Python):

def main():
    from collections import deque

    N, M, K = map(int, input().split())
    friends = [set() for _ in range(N + 1)]
    for _ in range(M):
        a, b = map(int, input().split())
        friends[a].add(b)
        friends[b].add(a)
    blocks = [set() for _ in range(N + 1)]
    for _ in range(K):
        c, d = map(int, input().split())
        blocks[c].add(d)
        blocks[d].add(c)

    friends_chain = []
    seen = [-1] * (N + 1)
    cnt = 0
    for person in range(1, N + 1):
        if seen[person] != -1:
            continue
        q = deque([person])
        friends_chain.append(set(q))
        while q:
            now = q.pop()
            seen[now] = cnt
            for next in friends[now]:
                if seen[next] != -1:
                    continue
                friends_chain[-1].add(next)
                q.append(next)
        cnt += 1

    for person in range(1, N + 1):
        res = friends_chain[seen[person]]
        tmp_ans = len(res) - len(friends[person]) - 1
        for block in blocks[person]:
            tmp_ans -= 1 if block in res else 0
        print(tmp_ans, end=' ')


if __name__ == '__main__':
    main()

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)

    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)
arr=[0]*n
for i in range(m):
    a,b=map(int, input().split())
    uf.union(a-1,b-1)
    arr[a-1]+=1
    arr[b-1]+=1
for i in range(k):
    c,d=map(int, input().split())
    if uf.same(c-1,d-1):
        arr[c-1]+=1
        arr[d-1]+=1
for i in range(n):
    print(uf.size(i)-arr[i]-1)

Solution (Python):
def makeRelation():
  visited=[False]*(N+1)
  g=0 
  for n in range(1,N+1):
    if visited[n]:
      continue
    q={n}
    D.append(set())
    while q:
      j=q.pop()
      for i in F[j]: 
        if not visited[i]:
          visited[i]=True
          q.add(i)
          D[g]|={i}
    g+=1
    
def main():
  makeRelation()
  
  for g in D:
    for d in g:
      ans[d]=len(g) - len(F[d]) - len(g&B[d]) - 1
  print(*ans[1:])


if __name__=='__main__':
  N, M, K = map(int, input().split())
  F=[set() for n in range(N+1)]
  AB=[list(map(int, input().split())) for m in range(M)]
  for a,b in AB:
    F[a].add(b)
    F[b].add(a)
  B=[set() for n in range(N+1)]
  CD=[list(map(int, input().split())) for k in range(K)]
  for c,d in CD:
    B[c].add(d)
    B[d].add(c)
  D=[]
  
  
  ans=[0]*(N+1)
  main()

Solution (Python):
from collections import Counter

class union_find():
    def __init__(self,n):
        self.n=n
        
        
        self.par=[-1 for i in range(n)]
        self.rank=[0]*(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.par[x]>self.par[y]:
          x,y=y,x
          
        self.par[x]+=self.par[y]
        self.par[y]=x

    def same(self,x,y):
        return self.find(x) == self.find(y)
    
    def size(self,x):
      return -self.par[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 roots(self):
      return [i for i, x in enumerate(self.par) if x<0]
    
    def all_group_member(self):
      return {r:self.members(r) for r in self.roots()}
      
n,m,k=map(int,input().split())
uf=union_find(n)
good=[0 for _ in range(n)]
for _ in range(m):
  a,b=map(int,input().split())
  uf.union(a-1,b-1)
  good[a-1]+=1
  good[b-1]+=1
  
  
ans=[0  for _ in range(n)]
    
    
bad=[0 for _ in range(n)]
for _ in range(k):
  p,q=map(int,input().split())
  if uf.same(p-1,q-1):
    
    bad[p-1]+=1
    bad[q-1]+=1


ans1=[]
for u in range(n):
  C=uf.size(u)
  
  ans1.append(str(C-1-bad[u]-good[u]))
  
print(' '.join(ans1))

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

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return
        elif self.rank[x-1] > self.rank[y-1]:
            self.par[x-1] += self.par[y-1]
            self.par[y-1] = x
        else:
            self.par[y-1] += self.par[x-1]
            self.par[x-1] = y
            if self.rank[x-1] == self.rank[y-1]:
                self.rank[y-1] += 1

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

    def count(self, x):
        return -self.par[self.find(x)-1]

from collections import deque

N,M,K=map(int,input().split())
U=UnionFind(N)
q=deque([])
for _ in range(M):
  a,b=map(int,input().split())
  U.union(a,b)
  deque.append(q,(a,b))
G=[set([]) for _ in range(N)]
for _ in range(M):
  a,b=deque.pop(q)
  if U.same(a,b):
    G[a-1].add(b)
    G[b-1].add(a)
for _ in range(K):
  a,b=map(int,input().split())
  if U.same(a,b):
    G[a-1].add(b)
    G[b-1].add(a)
ans=[0]*N
for i in range(1,N+1):
  ans[i-1]=U.count(i)-len(G[i-1])-1
print(*ans)

Solution (Python):
from collections import Counter
 
N, M, K = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(M)]
CD = [list(map(int, input().split())) for _ in range(K)]
 
friend_g = [set() for i in range(N)]
for a, b in AB:
    a, b = a-1, b-1
    friend_g[a].add(b)
    friend_g[b].add(a)
friend_count = [len(s) for s in friend_g]
 
g_nums = [-1]*N
current_g_num = 0
for i in range(N):
    if g_nums[i] == -1:
        g_nums[i] = current_g_num
        q = [i]
        while q:
            t = q.pop()
            for friend in friend_g[t]:
                if g_nums[friend] == -1:
                    g_nums[friend] = current_g_num
                    q.append(friend)
                
        current_g_num += 1
 
block_count = [0]*N
for c, d in CD:
    c, d = c-1, d-1
    if g_nums[c] == g_nums[d]:
        block_count[c] += 1
        block_count[d] += 1
 
g_nums_counter = Counter(g_nums)
print(*(g_nums_counter[g_nums[i]] - friend_count[i] - block_count[i] - 1 for i in range(N)))

Solution (Python):
from collections import Counter
import sys

n, m, k = map(int, input().split())
F = [[] for _ in range(n)]
B = [[0] for _ in range(n)]

sys.setrecursionlimit(10**9)

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

rks = [0]*(n)

def dfs(s,r):
    if rks[s] == 0:
        rks[s] = r
    for i in F[s]:
        if rks[i-1] != 0:
            continue
        dfs(i-1,r)

r = 0
for i in range(n):
    if rks[i] == 0:
        r += 1
        dfs(i,r)

for _ in range(k):
    c, d = map(int, input().split())
    if rks[c-1] == rks[d-1]:
        B[c-1][0] += 1
        B[d-1][0] += 1

counter = Counter(rks)
for i in range(n):
    print(counter[rks[i]] - len(F[i]) - (B[i][0]) - 1)

Solution (Python):
import sys
from math import *
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def main():
    n, m, k = map(int, input().split())
    fgraph = [list() for i in range(n)]
    bgraph = [list() for i in range(n)]
    cgraph = [list() for i in range(n)]
    
    rks = [None] *n
    sys.setrecursionlimit(10**9)
    
    def dfs(graph,s,r):
        if rks[s] is None:
            rks[s] = r
        for i in range(len(graph[s])):
            if rks[graph[s][i]-1] is not None:
                continue
            dfs(graph, graph[s][i]-1,r)

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

    
    
    
    c = -1
    for i in range(n):
        if rks[i] is None:
            c += 1
            dfs(fgraph, i, c)
    
    for i in range(k):
        c,d = map(int, input().split())
        if rks[c-1] == rks[d-1]:
            bgraph[d-1].append(c)
            bgraph[c-1].append(d)

    counter = Counter(rks)
    for i in range(n):
        
        
        
        
        print(counter[rks[i]] - len(fgraph[i]) - len(bgraph[i]) - 1)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(2*100)

def main():
    
    N, M, K = map(int, input().split())
    G = {v: deque([]) for v in range(N)}
    G_original = {v: deque([]) for v in range(N)}
    for _ in range(M):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        G[a].append(b)
        G[b].append(a)
        G_original[a].append(b)
        G_original[b].append(a)

    Block = {v: deque([]) for v in range(N)}
    for _ in range(K):
        c, d = map(int, input().split())
        c -= 1
        d -= 1
        Block[c].append(d)
        Block[d].append(c)

    
    stack = []
    color = {v: None for v in range(N)}
    col2v = {col: set() for col in range(N)}
    
    def dfs(j, col):
        if color[j] is not None:
            return
        
        col2v[col] = set()
        stack.append(j)
        color[j] = col
        col2v[col].add(j)
        while stack:
            s = stack[-1]
            if not G[s]:
                stack.pop()
                continue
            g_NO  = G[s].popleft()
            if color[g_NO] is not None:
                continue
            color[g_NO] = col
            col2v[col].add(g_NO)
            
            stack.append(g_NO)
    
    
    
        
    
    
    
    
    
        
    c = 0
    for start in range(N):
        dfs(start, c)
        c += 1
    
    ans = []
    for v in range(N):
        
        
        
        
        
        
        
        tmp = col2v[color[v]]
        tmp2 = tmp & set(Block[v])
        tmp3 = tmp & set(G_original[v])
        print((len(tmp)-len(tmp2)-len(tmp3)-1), end=" ")
        
        
        
    
main()

Solution (Python):
from collections import Counter

N, M, K = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(M)]
CD = [list(map(int, input().split())) for _ in range(K)]

friend_g = [set() for i in range(N)]
for a, b in AB:
    a, b = a-1, b-1
    friend_g[a].add(b)
    friend_g[b].add(a)
friend_count = [len(s) for s in friend_g]

g_nums = [-1]*N
current_g_num = 0
for i in range(N):
    if g_nums[i] == -1:
        g_nums[i] = current_g_num
        q = [i]
        while q:
            t = q.pop()
            for friend in friend_g[t]:
                if g_nums[friend] == -1:
                    g_nums[friend] = current_g_num
                    q.append(friend)
                
        current_g_num += 1

block_count = [0]*N
for c, d in CD:
    c, d = c-1, d-1
    if g_nums[c] == g_nums[d]:
        block_count[c] += 1
        block_count[d] += 1

g_nums_counter = Counter(g_nums)
print(*(g_nums_counter[g_nums[i]] - friend_count[i] - block_count[i] - 1 for i in range(N)))

Solution (Python):
from collections import defaultdict

class UnionFind():
    def __init__(self, n=0):
        self.d = [-1]*n
    
    def find(self, x):
        if self.d[x] < 0: return x
        self.d[x] = self.find(self.d[x])
        return self.d[x]

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

    def same(self, x,y): return self.find(x)==self.find(y)
    def size(self,x): return -self.d[self.find(x)]
    
N,M,K=map(int,input().split())
uf=UnionFind(N+1)
n_friends=defaultdict(int)
for i in range(M):
  a,b=map(int,input().split())
  uf.unite(a,b)
  n_friends[a] += 1
  n_friends[b] += 1
  
ans = [uf.size(i)-n_friends[i]-1 for i in range(N+1)]

for i in range(K):
  c,d=map(int,input().split())
  if uf.same(c,d):
    ans[c] -= 1
    ans[d] -= 1
  
print(*ans[1:])