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)

    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())
    friend = [[] for i in range(n)]
    block = [[] for i in range(n)]

    for i in range(m):
        a,b = map(lambda x: int(x)-1,input().split())
        friend[a].append(b)
        friend[b].append(a)
    
    
    for i in range(k):
        c,d = map(lambda x:int(x)-1,input().split())
        block[c].append(d)
        block[d].append(c)
    
    

    un = UnionFind(n)
    
    for i in range(len(friend)):
        for j in range(len(friend[i])):
            
            un.union(i,friend[i][j])
    
    ans = []
    for i in range(len(block)):
        cnt = 0
        for j in range(len(block[i])):
            
            if un.find(i) == un.find(block[i][j]):
                cnt += 1
        ans.append(str(un.size(i)-len(friend[i]) - cnt - 1))

    
    
    
    
    
    

    print(' '.join(ans))

    return


if __name__ == "__main__":
    main()

Solution (Python):
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
import math
import bisect
import numpy as np
from collections import defaultdict, deque
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)

INF = float("inf")


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())
    graph_friends =[[] for _ in range(N)]
    uf_friends = UnionFind(N)
    for _ in range(M):
        a, b = [int(i) - 1 for i in input().split()]
        graph_friends[a].append(b)
        graph_friends[b].append(a)
        uf_friends.union(a, b)

    graph_block = [[] for _ in range(N)]
    for _ in range(K):
        c, d = [int(i) - 1 for i in input().split()]
        graph_block[c].append(d)
        graph_block[d].append(c)

    ans = [0] * N
    for i in range(N):
        size = uf_friends.size(i) - 1
        for f in graph_friends[i]:  
            if uf_friends.same(i, f):  
                size -= 1
        for b in graph_block[i]:  
            if uf_friends.same(i, b):  
                size -= 1
        ans[i] = size
    print(*ans)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import defaultdict, deque



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

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

dame = [set() for _ in range(N)]
uf = UnionFind(N)

for _ in range(M):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    uf.union(a, b)
    dame[a].add(b)
    dame[b].add(a)

for _ in range(K):
    c, d = list(map(int, input().split()))
    c -= 1
    d -= 1
    if uf.find(c) == uf.find(d):
        dame[c].add(d)
        dame[d].add(c)

ans = []
for i in range(N):
    ans.append(uf.size(i) - len(dame[i]) -1 )

for val in ans:
    print(val, end=" ")
print("\n")

Solution (Python):
N, M, K = map(int, input().split())
ans = [0] * (N + 1)
child = {i:[] for i in range(1, N+1)}
isChecked = [0] * (N + 1)
isBlocked = [set() for _ in range(N+1)]

for _ in range(M):
    a, b = map(int, input().split())
    child[a].append(b)
    child[b].append(a)
for _ in range(K):
    c, d = map(int, input().split())
    isBlocked[c].add(d)
    isBlocked[d].add(c)
for i in range(1, N+1):
    if isChecked[i]:
        continue
    isChecked[i] = 1
    x = set([i])
    ch = child[i].copy()
    while ch:
        c = ch.pop()
        if isChecked[c]:
            continue
        isChecked[c] = 1
        x.add(c)
        ch.extend(child[c])
    for j in x:
        ans[j] = len(x) - 1 - len(child[j]) - len(x & isBlocked[j])
print(*ans[1:])

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

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

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

visited = [0] * N
cnt = 0

for i in range(N):
    if visited[i] != 0: continue
    temp = [i]
    cnt += 1
    visited[i] = cnt
 
    while temp:
        x = temp.pop()
        for y in lstab[x]:
            if visited[y] != 0:continue
            temp.append(y)
            visited[y] = cnt

numcd = [ 0 ] * N
for _ in range(K):
    c, d = map(int, input().split())
    if visited[c-1] == visited[d-1]:
        numcd[c-1] += 1
        numcd[d-1] += 1    
    
ans = [0] * N
cnt = Counter(visited)

for i in range(N):
    ans[i] = cnt[visited[i]] - 1 - len(lstab[i]) - numcd[i]
 
print(*ans)

Solution (Python):
from collections import deque, Counter
N, M, K = list(map(int, input().split()))
F = [[] for _ in range(N)]
B = [[] for _ in range(N)]

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

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



connect_group = {}

for i in range(N):
    if connect_group.get(i) is not None:
        continue
    stack = deque()
    stack.append(i)
    connect_group[i] = i
    p = -1    
    while len(stack):
        j = stack.pop()
        connect_group[j] = i
        for k in F[j]:
            if connect_group.get(k) is None:
                stack.append(k)
                connect_group[k] = i


ans = []
connect_len = Counter(connect_group.values())
for i in range(N):
    g = connect_group[i]
    l = connect_len[g]
    x = 0
    for j in set(F[i]).union(set(B[i])):
        if g == connect_group[j]:
            x += 1
    ans.append(str(l - x - 1))

print(' '.join(ans))

Solution (Python):
class UnionFindTree:
    
    def __init__(self, n):
        if n == 0:
            raise Exception("n is more than 1")
        self.parent = [i for i in range(n)]
        self.rank = [0]*n
        self.num = {}
        for i in range(n):
            self.num.update({i:1})
    
    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[x] = y
            self.num[y] += self.num[x]
            del self.num[x]
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.num[x] += self.num[y]
            del self.num[y]
        
    
    def same(self, x, y):
        X = self.find(x)
        Y = self.find(y)
        return X == Y

def add_dict(d, a, b):
    d[a].append(b)
    d[b].append(a)

def Main(N, M, K, A, B, C, D):
    uft = UnionFindTree(N)
    df = {}
    db = {}
    for i in range(N):
        df.update({i:[]})
        db.update({i:[]})
    for i in range(M):
        uft.unite(A[i]-1, B[i]-1)
        add_dict(df, A[i]-1, B[i]-1)
    for i in range(K):
        add_dict(db, C[i]-1, D[i]-1)
    ans = []
    for i in range(N):
        num_b = 0
        for e in db[i]:
            if uft.same(i, e):
                num_b += 1
        a = uft.num[uft.find(i)] - len(df[i]) - num_b - 1
        ans.append(str(a))
    return ans
                    
def main():
    N, M, K = map(int, input().split())
    A = []
    B = []
    C = []
    D = []
    for i in range(M):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
    for i in range(K):
        c, d = map(int, input().split())
        C.append(c)
        D.append(d)
    out = Main(N, M, K, A, B, C, D)
    print(" ".join(out))

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 = list(map(int,input().split()))

ARR = []

for i in range(M):
    ARR.append(list(map(int,input().split())))

BRR = []
for i in range(K):
    BRR.append(list(map(int,input().split())))

unionFind = UnionFind(N)

fl = [[] for i in range(N)]
bl = [[] for i in range(N)]
for ar in ARR:
    fromNode = ar[0] - 1
    toNode = ar[1] - 1
    unionFind.union(fromNode, toNode)
    fl[fromNode].append(toNode)
    fl[toNode].append(fromNode)

for br in BRR:
    fromNode = br[0] - 1
    toNode = br[1] - 1
    bl[fromNode].append(toNode)
    bl[toNode].append(fromNode)

result = []
for i in range(N):
    size = unionFind.size(i) - 1


    for f in fl[i]:
        if unionFind.same(i,f):
            size = size - 1
    for b in bl[i]:
        if unionFind.same(i,b):
            size = size - 1

    result.append(str(size))

print(" ".join(result))

Solution (Python):
from collections import deque,Counter
n,m,k = map(int,input().split())
G = [[] for _ in range(n)]

exc = [0]*n
for _ in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)
    exc[a] += 1
    exc[b] += 1

stk = deque()
grp = [-1]*n
grpnum = 0
def dfs(s,g):
    stk.append(s)
    grp[s] = g
    while stk:
        cur = stk.pop()
        for nxt in G[cur]:
            if grp[nxt] != -1: continue
            grp[nxt] = g
            stk.append(nxt)

for i in range(n):
    if grp[i] != -1: continue
    dfs(i,grpnum)
    grpnum += 1
cnt = Counter(grp)

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

ans = [cnt[grp[i]] - exc[i] - 1 for i in range(n)]
print(*ans)

Solution (Python):
from collections import deque, defaultdict
import sys
input = sys.stdin.buffer.readline

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


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

NIL = -1
color = [NIL]*n
def dfs(r, c):
    S = deque([])
    S.append(r)
    color[r] = c
    while S:
        u = S.popleft()
        for v in G[u]:
            if color[v] == NIL:
                color[v] = c
                S.append(v)
                
def make_color():
    id = 1
    for u in range(n):
        if color[u] == NIL:
            dfs(u, id)
            id += 1
            
make_color()



count = defaultdict(lambda:0)
for i in range(n):
    count[i] = 0
for i in range(n):
    count[color[i]] += 1


block = defaultdict(lambda:deque([]))
for _ in range(k):
    c, d = map(int, input().split())
    c, d = c-1, d-1
    block[c].append(d)
    block[d].append(c)

temp = []
for i in range(n):
    x = count[color[i]] - 1
    y =  len(G[i])
    z = 0 
    for v in block[i]:
        if color[i] == color[v]:
            z += 1
    temp.append(x-y-z)
print(*temp)

Solution (Python):
from collections import deque, defaultdict
import sys
input = sys.stdin.buffer.readline

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


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

NIL = -1
color = [NIL]*n
def dfs(r, c):
    S = deque([])
    S.append(r)
    color[r] = c
    while S:
        u = S.popleft()
        for v in G[u]:
            if color[v] == NIL:
                color[v] = c
                S.append(v)
                
def make_color():
    id = 1
    for u in range(n):
        if color[u] == NIL:
            dfs(u, id)
            id += 1
            
make_color()



count = defaultdict(lambda:0)
for i in range(n):
    count[i] = 0
for i in range(n):
    count[color[i]] += 1


block = defaultdict(lambda:deque([]))
for _ in range(k):
    c, d = map(int, input().split())
    c, d = c-1, d-1
    block[c].append(d)
    block[d].append(c)

temp = []
for i in range(n):
    x = count[color[i]] - 1
    y =  len(G[i])
    z = 0 
    for v in block[i]:
        if color[i] == color[v]:
            z += 1
    temp.append(x-y-z)
print(*temp)

Solution (Python):
class DisjointSet:
    def __init__(self,n):
        self.parent = [i for i in range(n)]
        self.siz = [1]*n

    def root(self,x):
        if x != self.parent[x]: 
            self.parent[x] = self.root(self.parent[x])
        return self.parent[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
        if self.siz[x] < self.siz[y]: 
            x,y = y,x
        self.parent[y] = x
        self.siz[x] += self.siz[y]

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

n,m,k = map(int,input().split())
cnt = [0]*n
ds = DisjointSet(n)
for _ in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    cnt[a] += 1
    cnt[b] += 1
    ds.unite(a,b)
for _ in range(k):
    c,d = map(int,input().split())
    c -= 1
    d -= 1
    if ds.same(c,d):
        cnt[c] += 1
        cnt[d] += 1
ans = [ds.size(i) - cnt[i] - 1 for i in range(n)]
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

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

def solve(uf, except_list):
    ret = [0]
    for i in range(1, N + 1):
        ret.append(uf.size(i) - 1 - len(except_list[i]))
    return ret

if __name__ == '__main__':
    N, M, K = map(int, input().split())
    except_list = [[] for _ in range(N + 1)]
    uf = UnionFind(N + 1)

    for _ in range(M):
        a, b = map(int, input().split())
        except_list[a].append(b)
        except_list[b].append(a)
        uf.union(a, b)

    for _ in range(K):
        c, d = map(int, input().split())
        if not uf.same(c, d):
            continue
        except_list[c].append(d)
        except_list[d].append(c)

    for ans in solve(uf, except_list)[1:]:
        print(ans, end=' ')

Solution (Python):


import sys



















def main():
    mod = 1000000007                  
    inf = float('inf')
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())


    class UnionFind:
        def __init__(self, n):
            self.table = [i for i in range(n)]
            self.rank = [0] * n
            self.group_size = [1] * n
        
        def find_root(self, i):
            if self.table[i] == i:
                return i
            root = self.find_root(self.table[i])
            self.table[i] = root    
            return root
        
        def is_same(self, x, y):
            return self.find_root(x) == self.find_root(y)
        
        def union(self, x, y):
            s = self.find_root(x)
            t = self.find_root(y)
            if s == t:
                return False
            else:
                if self.rank[s] > self.rank[t]:
                    s, t = t, s
                self.table[s] = t
                self.group_size[t] += self.group_size[s]
                if self.rank[s] == self.rank[t]:
                    self.rank[t] += 1
                return True
        
        def num_of_members(self, i):
            root = self.find_root(i)
            return self.group_size[root]
    

    n, m, k = lmi()
    adj_friend = [[] for _ in range(n)]
    for _ in range(m):
        a, b = mi_0()
        adj_friend[a].append(b)
        adj_friend[b].append(a)
    adj_rival = [[] for _ in range(n)]
    for _ in range(k):
        c, d = mi_0()
        adj_rival[c].append(d)
        adj_rival[d].append(c)
    
    uf = UnionFind(n)
    for i, elm in enumerate(adj_friend):
        for j in elm:
            if i < j:
                uf.union(i, j)
    
    for i in range(n):
        connected = uf.num_of_members(i)
        connected_rival = 0
        for rival in adj_rival[i]:
            if uf.is_same(i, rival):
                connected_rival += 1
        
        print(connected - connected_rival - len(adj_friend[i]) - 1, end=' ')    
    print('')
    

if __name__ == "__main__":
    main()

Solution (Python):
def main():
    n, m, k = map(int, input().split())
    fb = [0]*(n+1)
    uf = UnionFind(n)
    for i in range(m):
        a, b = map(int, input().split())
        fb[a] += 1
        fb[b] += 1
        uf.unite(a, b)
    for i in range(k):
        c, d = map(int, input().split())
        
        if uf.same(c, d):
            fb[c] += 1
            fb[d] += 1
    ans = [uf.size(i)-1-fb[i] for i in range(1, n+1)]
    print(" ".join(list(map(str, ans))))


class UnionFind:
    __slots__ = ["data"]
    
    def __init__(self, n=0):
        self.data = [-1]*(n+1)
    
    def root(self, x):
        if self.data[x] < 0:
            return x
        self.data[x] = self.root(self.data[x])
        return self.data[x]
    
    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            if self.data[x] < self.data[y]:
                self.data[x] += self.data[y]
                self.data[y] = x
            else:
                self.data[y] += self.data[x]
                self.data[x] = y
    
    def same(self, x, y):
        return self.root(x) == self.root(y)
    
    def size(self, x):
        return -self.data[self.root(x)]



if __name__ == "__main__":
    main()

Solution (Python):
import sys
from collections import Counter
input = lambda: sys.stdin.readline().rstrip()
n, m, k = map(int, input().split())

fgraph = [list() for _ in range(n)]  
bgraph = [list() for _ in range(n)]  
cgraph = [list() for _ in range(n)]  
sys.setrecursionlimit(10**9)
rks = [None]*n


def dfs(graph, s, r):  
    if rks[s] is None:
        rks[s] = r
    for j in range(len(graph[s])):
        if rks[graph[s][j] - 1] is not None:
            continue
        dfs(graph, graph[s][j]-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[c-1].append(d)
        bgraph[d-1].append(c)

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

Solution (Python):
from collections import deque
n,m,k = map(int,input().split())
friend = [set() for i in range(n)]
block = [set() for i in range(n)]

for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    friend[a].add(b)
    friend[b].add(a)
for i in range(k):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    block[a].add(b)
    block[b].add(a)

stack = deque()
ans = [0] * n
visited = [0] * n

for i in range(n):
    if visited[i]:continue
    now = {i}
    visited[i] = 1
    stack.append(i)
    while stack:
        num = stack.pop()
        for j in friend[num]:
            if visited[j] == 0:
                stack.append(j)
                visited[j] = 1
                now.add(j)
    for i in now:
        ans[i] = len(now)-len(now&friend[i])-len(now&block[i])-1
for answer in ans:
    print(answer,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())
N, M, K = map(int, input().split())
num_fri = [0] * N
union = UnionFind(N)
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    num_fri[a] += 1
    num_fri[b] += 1
    union.union(a, b)
for i in range(K):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if union.same(a, b):
        num_fri[a] += 1
        num_fri[b] += 1
for i in range(N):
    print(union.size(i) - 1 - num_fri[i], end=' ')

Solution (Python):
from collections import deque
import sys
input = sys.stdin.readline
n, m, k = map(int, input().split())
friend = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    friend[a-1].append(b-1)
    friend[b-1].append(a-1)
check = [0]*n
union = [-1]*n
union[0] = 0
for i in range(n):
    if check[i]: continue
    que = deque([i])
    while que:
        u = que.popleft()
        for v in friend[u]:
            if check[v]: continue
            union[v] = i
            check[v] = 1
            que.append(v)
            
brock = [[] for _ in range(n)]
for _ in range(k):
    c, d = map(int, input().split())
    if union[c-1] == union[d-1]:
        brock[c-1].append(d-1)
        brock[d-1].append(c-1)
        
ans = [0]*n
check = [0]*n
for i in range(n):
    if check[i] or union[i]==-1: continue
    que = deque([i])
    for j in range(i+1, n):
        if union[j] == union[i]: que.append(j)
    res = len(que)
    while que:
        u = que.popleft()
        check[u] = 1
        ans[u] = res-len(friend[u])-len(brock[u])-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())


friend_uf = UnionFind(N)
not_list = [[] for i in range(N+1)]
ans_list = [0] * (N)


for i in range(M):
    a, b = map(int, input().split())
    friend_uf.union(a-1, b-1)
    not_list[a].append(b)
    not_list[b].append(a)


for i in range(K):
    c, d = map(int, input().split())
    if friend_uf.same(c-1, d-1):
        not_list[c].append(d)
        not_list[d].append(c)


for i in range(1, N+1):
    group_size = friend_uf.size(i-1)
    not_size = not_list[i]
    ans = group_size - len(set(not_size)) - 1
    ans_list[i-1] = ans
ans_list = list(map(str, ans_list))
print(" ".join(ans_list))

Solution (Python):
import sys


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

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

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

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

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


input = sys.stdin.readline
N, M, K = map(int, input().split())
F = [[] for _ in [0]*N]
B = [[] for _ in [0]*N]

uf = UnionFind(N)

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

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

for i in range(N):
    ans = uf.size(i) - 1
    ans -= len(F[i])
    for b in B[i]:
        if uf.same(i, b):
            ans -= 1
    print(ans, end=' ')