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)

n,m,k = map(int,input().split())
g = [[] for _ in range(n)]
uf = UnionFind(n)

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

Solution (Python):
n, m, k = map(int, input().split())
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.par = [-1 for i in range(self.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 unite(self, x, y):
        p = self.find(x)
        q = self.find(y)
        if p == q:
            return None
        if p > q:
            p, q = q, p
        self.par[p] += self.par[q]
        self.par[q] = p
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def size(self, x):
        return -self.par[self.find(x)]
UF = UnionFind(n)
f_or_b = [0] * n
for i in range(m):
    a, b = map(int, input().split())
    UF.unite(a - 1, b - 1)
    f_or_b[a - 1] += 1
    f_or_b[b - 1] += 1
for i in range(k):
    c, d = map(int, input().split())
    if UF.same(c - 1, d - 1):
        f_or_b[c - 1] += 1
        f_or_b[d - 1] += 1
for i in range(n):
    print(UF.size(i) - f_or_b[i] - 1, 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())
V = [[] for i in range(n+1)]
W = [0]*(n+1)
uf = UnionFind(n+1)
for _ in range(m):
    a,b = map(int,input().split())
    V[a].append(b)
    V[b].append(a)
    uf.union(a,b)
for _ in range(k):
    c,d = map(int,input().split())
    if uf.find(d) == uf.find(c):
        W[c] += 1
        W[d] += 1
    
for i in range(1,n+1):
    ans = uf.size(i) - len(V[i]) - W[i] - 1
    print(ans,end="")
    print(" ",end="")
print()

Solution (Python):
from collections import deque

n,m,k = map(int,input().split())
next = [[] for i in range(n)]
num_next= [0]*n
block = [[] for i in range(n)]
for i in range(m):
  x,y = map(int,input().split())
  next[y-1].append(x-1)
  next[x-1].append(y-1)
  num_next[x-1] += 1
  num_next[y-1] += 1
  
for j in range(k):
  x,y = map(int,input().split())
  block[y-1].append(x-1)
  block[x-1].append(y-1)
friend = []
num = {}  
mark = ['t']*n
for i in range(n):
  if mark[i] == 't':
    
    mark[i] = i
    s = 1
    que = deque([i])
    while que:
      p = que.popleft()
      for x in next[p]:
        if mark[x] == 't':
          mark[x] = mark[p]
          s += 1
          que.append(x)
    num[i] = s      

ans = []
for i in range(n):
  l = num[mark[i]] -1-num_next[i]
  for y in block[i]:
    if mark[y] == mark[i]:
      l -= 1
  ans.append(str(l))    
      
print(' '.join(ans))

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

    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.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
                
    def is_same_group(self, x, y):
        return self.find_root(x) == self.find_root(y)

    def count(self, x):
        return -self.root[self.find_root(x)]
    
f=lambda:map(int,input().split())
N,M,K=f()
uf=UnionFind(N)
bro=[0]*(N+1)
AB=[]
for _ in [0]*M:
    a,b=f()
    AB.append((a,b))
    uf.unite(a,b)
for a,b in AB:
    if uf.is_same_group(a,b):
        bro[a]+=1
        bro[b]+=1
for _ in [0]*K:
    c,d=f()
    if uf.is_same_group(c,d):
        bro[c]+=1
        bro[d]+=1
for i in range(1,N+1):
    print(uf.count(i)-1-bro[i])

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

f_adj_list = [[] for i in range(n)]
b_adj_list = [[] for i in range(n)]

for i in range(m):
  _, __ = map(int, input().split())
  _ -= 1
  __ -= 1
  f_adj_list[_].append(__)
  f_adj_list[__].append(_)
  
for j in range(k):
  _, __ = map(int, input().split())
  _ -= 1
  __ -= 1
  b_adj_list[_].append(__)
  b_adj_list[__].append(_)
  
  
group_id = [None for i in range(n)]
for i in range(n):
  if group_id[i] is not None: continue
  
  newly_visited = [i]
  group_id[i] = i
  while len(newly_visited) > 0:
    now = newly_visited.pop()
    for j in f_adj_list[now]:
      if group_id[j] is not None: continue
      newly_visited.append(j)
      group_id[j] = i





from collections import Counter
cnt = Counter(group_id)


ans_list = []
for i in range(n):
  ans = cnt[group_id[i]]
  ans -= 1 
  ans -= len(f_adj_list[i]) 
  for j in b_adj_list[i]:
    if group_id[i] == group_id[j]:
      ans -= 1
  ans_list.append(ans)

print(" ".join(map(str, ans_list)))

Solution (Python):
from sys import stdin

def getval():
    n,m,k = map(int,stdin.readline().split())
    a = [list(map(int,stdin.readline().split())) for i in range(m)]
    c = [list(map(int,stdin.readline().split())) for i in range(k)]
    return n,m,k,a,c 

def main(n,m,k,a,c):
    
    friends = [[] for i in range(n)]
    for i in a:
        friends[i[0]-1].append(i[1]-1)
        friends[i[1]-1].append(i[0]-1)
    
    
    frgroups = []
    visited = [False for i in range(n)]
    for i in range(n):
        if visited[i]:
            continue
        q = [i]
        temp = [i]
        visited[i] = True
        while q:
            idx = q.pop(0)
            adj = friends[idx]
            for j in adj:
                if visited[j]:
                    continue
                visited[j] = True
                q.append(j)
                temp.append(j)
        frgroups.append(temp)    

    
    groups = [-1 for i in range(n)]
    for i in range(len(frgroups)):
        for j in frgroups[i]:
            groups[j] = i 
            
    
    
    ans = [len(frgroups[groups[i]])-1-len(friends[i]) for i in range(n)]
    for i in c:
        if groups[i[0]-1]==groups[i[1]-1]:
            ans[i[0]-1] -= 1
            ans[i[1]-1] -= 1
    s = str(ans[0])
    for i in range(1,n):
        s += " " + str(ans[i])
    print(s)
    

if __name__=="__main__":
    n,m,k,a,c = getval()
    main(n,m,k,a,c)

Solution (Python):
import collections
N, M, K = map(int, input().split())
friend = [[] for i in range(N)]
block = [[] for i in range(N)]
graph = [-1] * N
for i in range(M):
  a, b = map(int, input().split())
  friend[a-1].append(b-1)
  friend[b-1].append(a-1)
  
for i in range(K):
  c, d = map(int, input().split())
  block[c-1].append(d-1)
  block[d-1].append(c-1)
  


used = [True] * N
for i in range(N):
  if used[i]:
    q = [i]
    used[i] = False
    graph[i] = i
    while q:
      now = q.pop()
      for j in friend[now]:
        if used[j]:
          graph[j] = graph[now]
          q.append(j)
          used[j] = False
          
          

gg = dict(collections.Counter(graph))  


for i in range(N):
  nn = graph[i]
  size = gg[nn]
  ans = size - 1
  for j in friend[i]:
    if nn == graph[j]:
      ans -= 1
  for j in block[i]:
    if nn == graph[j]:
      ans -= 1
  print(ans, end = " ")

Solution (Python):
import collections
N, M, K = map(int, input().split())
friend = [[] for i in range(N)]
block = [[] for i in range(N)]
graph = [-1] * N
for i in range(M):
  a, b = map(int, input().split())
  friend[a-1].append(b-1)
  friend[b-1].append(a-1)
  
for i in range(K):
  c, d = map(int, input().split())
  block[c-1].append(d-1)
  block[d-1].append(c-1)
  


used = [True] * N
for i in range(N):
  if used[i]:
    q = [i]
    used[i] = False
    graph[i] = i
    while q:
      now = q.pop()
      for j in friend[now]:
        if used[j]:
          graph[j] = graph[now]
          q.append(j)
          used[j] = False
          
          

gg = dict(collections.Counter(graph))  


for i in range(N):
  nn = graph[i]
  size = gg[nn]
  ans = size - 1
  for j in friend[i]:
    if nn == graph[j]:
      ans -= 1
  for j in block[i]:
    if nn == graph[j]:
      ans -= 1
  print(ans, end = " ")

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

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

block = [[]]*k
for i in range(k):
    c,d = map(int,input().split())
    c -= 1
    d -= 1
    block[i] = (c,d)

ans = [uf.size(i) - 1 for i in range(n)]
for i,j in friend:
    if uf.same(i,j):
        ans[i] -= 1
        ans[j] -= 1
for i,j in block:
    if uf.same(i,j):
        ans[i] -= 1
        ans[j] -= 1

print(*ans)

Solution (Python):
class unionfind():

    def __init__(self,n):
        
        
        self.par=[-1 for i in range(n)]
        
    def root(self,x):
        
        par=self.par
        if par[x]<0:
            return x
        else:
            self.x = self.root(par[x])
            return self.x
        
    def unite(self,x,y):
        
        rx=self.root(x)
        ry=self.root(y)
        
        if rx==ry:
            return
        else:
            if self.par[rx]>self.par[ry]:
                rx,ry = ry,rx
                
            self.par[rx]+=self.par[ry]
            self.par[ry] = rx

            
    def same(self, x,y):
        return self.root(x) == self.root(y)
    
    def par_print(self):
        print(self.par)
        
    def count(self, x):
        return -self.par[self.root(x)]

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

friend = [[] for i in range(n)]
block = [[] for i in range(n)]

uf = unionfind(n)

for i in range(m):
    
    a,b = map(int,input().split())
    a-=1
    b-=1
    
    friend[a].append(b)
    friend[b].append(a)
    
    uf.unite(a,b)
    
    
    
for i in range(k):
    
    a,b = map(int,input().split())
    a-=1
    b-=1
    
    block[a].append(b)
    block[b].append(a) 
    
    
for i in range(n):
    
    ans = uf.count(i)-1 -len(friend[i])
    
    for j in block[i]:
        if uf.same(i,j):
            ans -= 1
    
    print(ans, end = " ")

Solution (Python):
class UnionFind:
    def __init__(self, N):
        self.N = N

        
        
        self.parent = [-1] * N

    def root(self, i):
        if self.parent[i] < 0:
            return i

        r = self.root(self.parent[i])
        self.parent[i] = r
        return r

    def unite(self, i, j):
        i = self.root(i)
        j = self.root(j)

        if i == j:
            return

        if i > j:
            i, j = j, i

        self.parent[i] += self.parent[j]
        self.parent[j] = i
        

    def same(self, i, j):
        return self.root(i) == self.root(j)

    def size(self, i):
        return -self.parent[self.root(i)]

    def roots(self):
        return [self.root(i) for i in range(self.N)]

    def groupcount(self):
        return len(set(self.roots()))

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

notfriend = [set() for _ in range(N)]
forest = UnionFind(N)


for i in range(M):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    notfriend[a].add(b)
    notfriend[b].add(a)

    forest.unite(a, b)


for i in range(K):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    if forest.same(a, b):
        notfriend[a].add(b)
        notfriend[b].add(a)

ans = ' '.join([str(forest.size(i) - 1 - len(notfriend[i])) for i in range(N)])
print(ans)

Solution (Python):
n,m,k = map(int,input().split())
root = [i for i in range(n)]
height = [1 for i in range(n)]
def find(n):
  sn = n
  while n != root[n]:
    n = root[n]
  root[sn] = n
  return n
def union(a,b):
  a = find(a)
  b = find(b)
  if a==b:
    return
  elif height[a]>=height[b]:
    height[a] += height[b]
    height[b] = 0
    root[b] = a
  else:
    height[b] += height[a]
    height[a] = 0
    root[a] = b
l = [set() for _ in range(n)]
for i in range(m):
  a,b = map(lambda x:int(x)-1,input().split())
  union(a,b)
  l[a].add(b)
  l[b].add(a)
for i in range(k):
  a,b = map(lambda x:int(x)-1,input().split())
  if find(a)==find(b):
    l[a].add(b)
    l[b].add(a)
print(*[height[find(i)]-len(l[i])-1 for i in range(n)])

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

par=[i for i in range(n)]
deep=[1]*n
size=[1]*n


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


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


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


def group_count(x):
  return size[find(x)]





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

cnt=[1]*n
for i in range(n):
  cnt[i]=group_count(i)
  
check=[0]*n
for j in range(k):
  c,d=map(int,input().split())
  if same(c-1,d-1):
    check[c-1]+=1
    check[d-1]+=1
for i in range(n):
  print(cnt[i]-1-len(es[i])-check[i],end=" ")

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

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 main():
    N, M, K = MI()
    uf = UnionFind(N)
    fri_list = [[]for _ in range(N)]
    blo_list = [[]for _ in range(N)]
    cnt_list = [0] * N
    for i in range(M):
        a, b = MI()
        a, b = a - 1, b - 1
        uf.union(a, b)
        fri_list[a].append(b)
        fri_list[b].append(a)
    for i in range(K):
        c, d = MI()
        c, d = c - 1, d - 1
        blo_list[c].append(d)
        blo_list[d].append(c)
    for i in range(N):
        cnt = uf.size(i)
        cnt -= len(fri_list[i]) + 1
        for b in blo_list[i]:
            if uf.same(i, b) == True:
                cnt -= 1
        cnt_list[i] = cnt
    print(' '.join(map(str, cnt_list)))


if __name__ == "__main__":
    main()

Solution (Python):

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1] * (n + 1)
        
    def find(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find(self.root[x])
            return self.root[x]
    
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.root[x] > self.root[y]:
            x, y = y, x
        self.root[x] += self.root[y]
        self.root[y] = x
        
    def is_same(self, x, y):
        return self.find(x) == self.find(y)
    
    def size(self, x):
        return -self.root[self.find(x)]
    
n, m, k = map(int, input().split())
friends = UnionFind(n)
f_or_b = [1] * (n + 1)
for i in range(m):
    a, b = map(int, input().split())
    friends.unite(a, b)
    f_or_b[a] += 1
    f_or_b[b] += 1
for i in range(k):
    c, d = map(int, input().split())
    if friends.is_same(c, d):
        f_or_b[c] += 1
        f_or_b[d] += 1
print(*[friends.size(i) - f_or_b[i] for i in range(1, n + 1)])

Solution (Python):
from collections import deque
f=lambda:map(int,input().split())
r=range
n,m,k=f()
F=[deque([])for _ in r(n)]
A=[0]*n
B=[-1]*n
C=[-1]*n
Q=deque([])
for _ in r(m):a,b=f();a-=1;b-=1;F[a].append(b);F[b].append(a);A[a]+=1;A[b]+=1
for i in r(n):
  Q.append(x:=i)
  y=0
  while Q:
    z=Q.popleft()
    if B[z]>-1:continue
    B[z]=x
    Q.extend(F[z])
    y+=1
  C[x]=y
D=[[B[i],C[B[i]]-A[i]-1]for i in r(n)]
for _ in r(k):
  c,d=f()
  c,d=c-1,d-1
  if D[c][0]==D[d][0]:D[c][1]-=1;D[d][1]-=1
print(*[d[1] for d in D])

Solution (Python):
class UnionFind:
    def __init__(self, n=0):
        self.d = [-1]*n
    def find(self, x):
        if self.d[x] < 0:
            return x
        else:
            self.d[x] = self.find(self.d[x])
            return self.d[x]
    def unite(self, x, y):
        x = self.find(x)
        y = 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())

deg = [0]*100005
uf = UnionFind(n)
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    deg[a] += 1
    deg[b] += 1
    uf.unite(a, b)
for _ in range(k):
    c, d = map(int, input().split())
    c -= 1
    d -= 1
    if uf.same(c, d):
        deg[c] += 1
        deg[d] += 1
for i in range(n):
    print(uf.size(i) - 1 - deg[i], end="")
    if i == n-1:
        print()
    else:
        print(" ", 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())
Network = UnionFind(N)
Friend = [0] * N  
BlockInNetwork = [0] * N  

for _ in range(M):  
    a, b = map(int, input().split())
    Network.union(a-1, b-1)
    Friend[a-1] += 1
    Friend[b-1] +=1

for _ in range(K): 
    c, d = map(int, input().split())
    if Network.same(c-1, d-1):  
        BlockInNetwork[c-1] += 1
        BlockInNetwork[d-1] += 1

out = [0] * N  
for i in range(N):
    out[i] = Network.size(i) - Friend[i] - BlockInNetwork[i] - 1
print(*out)

Solution (Python):
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.parents = [i for i in range(n+1)]
        self.size = [1]*(n+1)
    def find(self,x):
        if self.parents[x]==x:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]
    def unite(self,x,y):
        xRoot = self.find(x)
        yRoot = self.find(y)
        if xRoot == yRoot:
            return
        if self.size[xRoot]>self.size[yRoot]:
            self.parents[yRoot] = xRoot
            self.size[xRoot] += self.size[yRoot]
            self.size[yRoot] = 0
        else:
            self.parents[xRoot] = yRoot
            self.size[yRoot] += self.size[xRoot]
            self.size[xRoot] = 0

N,M,K = map(int,input().split())
tree = UnionFind(N)
friends = [list(map(int,input().split())) for _ in range(M)]
blocks = [list(map(int,input().split())) for _ in range(K)]
for a,b in friends:
    tree.unite(a,b)
for a,b in friends:
    tree.unite(a,b)

ans = [tree.size[tree.parents[i]]-1 for i in range(N+1)]
for a,b in friends:
    ans[a] -= 1
    ans[b] -= 1

for a,b in blocks:
    if tree.parents[a] == tree.parents[b]:
        ans[a] -= 1
        ans[b] -= 1

ans = [str(ans[i]) for i in range(1,N+1)]
print(" ".join(ans))

Solution (Python):
class UnionFind():
    def __init__(self, n):
        self.parents = [-1] * n
    
    def root(self, x):
        if self.parents[x] < 0:
            return x
        else:
            return self.root(self.parents[x])
    
    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return
        else:
            if x > y:
                x, y = y, x
            self.parents[x] += self.parents[y]
            self.parents[y] = x
            return

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)
f = [set() for _ in range(n)]
l = [set() for _ in range(n)]
for a, b in ab:
    a, b = a-1, b-1
    f[a].add(b)
    f[b].add(a)
    u.unite(a, b)
for c, d in cd:
    c, d = c-1, d-1
    l[c].add(d)
    l[d].add(c)
ans = [0] * n
for i in range(n):
    r = u.root(i)
    bl = 0
    for j in l[i]:
        if u.root(j) == r:
            bl += 1
    ans[i] = -u.parents[r] - len(f[i]) - bl - 1
print(' '.join(list(map(str, ans))))

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

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

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

        if x == y:
            return

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

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

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

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

    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())
tree=UnionFind(N)
not_friend_candidates=[]

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

for j in range(K):
  C,D=list(map(int,input().split()))
  C-=1
  D-=1
  not_friend_candidates.append([C,D])


ans=[0]*N
for i,j in not_friend_candidates:
  if tree.same(i,j):
    ans[i]-=1
    ans[j]-=1
for i in range(N):
  ans[i]+=tree.size(i)-1
print(*ans)

Solution (Python):
N,M,K=list(map(int,input().split()))
root=[i for i in range(N)]
height=[1 for i in range(N)]
l=[set() for i in range(N)]
mem=[0]*N
def find(n):
   f=n
   while n != root[n]:
      n=root[n]
   root[f]=n
   return n
def union(a,b):
   A=find(a)
   B=find(b)
   if A==B:
      return
   elif height[A]<height[B]:
      height[B]+=height[A]
      height[A]=0
      root[A]=B
   else:
      root[B]=A
      height[A]+=height[B]
      height[B]=0
def same(a,b):
   A=find(a)
   B=find(b)
   if A==B:
      l[a].add(b)
      l[b].add(a)
for i in range(M):
   a,b=list(map(int,input().split()))
   a-=1;b-=1
   l[a].add(b)
   l[b].add(a)
   union(a,b)
for j in range(K):
   a,b=list(map(int,input().split()))
   a-=1;b-=1
   same(a,b)
for i in range(N):
   print(height[find(i)]-len(l[i])-1,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())
Network = UnionFind(N)
Friend = [0] * N
BlockInNetwork = [0] * N

for _ in range(M):
    a, b = map(int, input().split())
    Network.union(a-1, b-1)
    Friend[a-1] += 1
    Friend[b-1] += 1

for _ in range(K):
    c, d = map(int, input().split())
    if Network.same(c-1, d-1):
        BlockInNetwork[c-1] += 1
        BlockInNetwork[d-1] += 1

out = [0]*N
for i in range(N):
    out[i]=Network.size(i)-Friend[i]-BlockInNetwork[i] - 1
print(*out)