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):
def main():
    n,m,k = map(int,input().split())
    friend = []
    block = []
    
    uf = UnionFind(n)
    
    exclude_i = [0] * n

    for _ in range(m):
        a,bb = map(int,input().split())
        
        uf.union(a-1,bb-1)
        friend.append([a-1,bb-1])

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


    for i, f in enumerate(friend):
        
        if uf.same(f[0],f[1]):
            exclude_i[f[0]] += 1
            exclude_i[f[1]] += 1



    for i in range(n):
        
        print(str(uf.size(i)-exclude_i[i]-1 ), end = " ")
    print("")

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


if __name__=='__main__':
    main()

Solution (Python):
def main():
    n,m,k = map(int,input().split())
    friend = []
    block = []
    
    uf = UnionFind(n)
    
    exclude_i = [0] * n

    for _ in range(m):
        a,bb = map(int,input().split())
        
        uf.union(a-1,bb-1)
        friend.append([a-1,bb-1])

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


    for i, f in enumerate(friend):
        
        if uf.same(f[0],f[1]):
            exclude_i[f[0]] += 1
            exclude_i[f[1]] += 1



    for i in range(n):
        
        print(str(uf.size(i)-exclude_i[i]-1 ), end = " ")
    print("")

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


if __name__=='__main__':
    main()

Solution (Python):
from collections import deque
n, m, k =map(int, input().split())

directcount = [0] * n 
visited = [-1]  * n 
colorcount = [-1] * n 

g = []
for _ in range(n):
    g.append(deque(list()))


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


q = deque(list()) 
for i in range(n):
    q.append(i)
    color = i
    cnt = 1
    while len(q) > 0:
        nextnode = q.popleft() 
        if visited[nextnode] != -1:
            continue
        visited[nextnode] = color
        q.extend(g[nextnode]) 
        cnt += 1
    
    colorcount[color]  = cnt - 1


res = [[visited[i], colorcount[visited[i]] - (directcount[i] + 1)] for i in range(n)]


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






print(" ".join(list(map(lambda x: str(x[1]), res))))

Solution (Python):
def main():
    n,m,k = map(int,input().split())
    
    
    
    fq = []
    
    bq = []
    uf = UnionFind(n)
    dame = [0] * n

    for _ in range(m):
        a,bb = map(int,input().split())
        
        
        uf.union(a-1,bb-1)
        fq.append([a-1,bb-1])

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


    for i, ff in enumerate(fq):
        if uf.same(ff[0],ff[1]):
            dame[ff[0]] += 1
            dame[ff[1]] += 1



    for i in range(n):
        print(str(uf.size(i)-dame[i]-1 ), end = " ")
    print("")

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


if __name__=='__main__':
    main()

Solution (Python):
def main():
    n,m,k = map(int,input().split())
    
    
    
    fq = []
    
    bq = []
    uf = UnionFind(n)
    dame = [0] * n

    for _ in range(m):
        a,bb = map(int,input().split())
        
        
        uf.union(a-1,bb-1)
        fq.append([a-1,bb-1])

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


    for i, ff in enumerate(fq):
        if uf.same(ff[0],ff[1]):
            dame[ff[0]] += 1
            dame[ff[1]] += 1



    for i in range(n):
        print(str(uf.size(i)-dame[i]-1 ), end = " ")
    print("")

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


if __name__=='__main__':
    main()

Solution (Python):
from collections import deque
n, m, k =map(int, input().split())

fd = dict()
directcount = [0] * n
visited = [[-1, -1] for i in range(n)]
q = deque(list())
g = []
for _ in range(n):
    g.append(deque(list()))

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

colorcount = [-1] * n

for i in range(n):
    q.append(i)
    color = i
    cnt = 1
    while len(q) > 0:
        
        nextnode = q.popleft() 
        if visited[nextnode][0] != -1:
            continue
        visited[nextnode] = [color, cnt]
        q.extend(g[nextnode]) 
        cnt += 1
    colorcount[color]  = cnt - 1

res = [[visited[i][0], colorcount[visited[i][0]]] for i in range(n)]

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

for i in range(n):
    res[i][1] -=  (directcount[i] + 1)
print(" ".join(list(map(lambda x: str(x[1]), res))))

Solution (Python):
from heapq import heappop, heappush
from collections import Counter


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


N, M, K = list(map(int, input().split()))
edges1 = [[] for _ in range(N + 1)]
edges2 = [[] for _ in range(N + 1)]
uf = UnionFind(N)

A, B = [], []
C, D = [], []
for _ in range(M):
    _a, _b = list(map(int, input().split()))
    A.append(_a)
    B.append(_b)
    uf.unite(_a, _b)
    edges1[_a].append(_b)
    edges1[_b].append(_a)

for _ in range(K):
    _c, _d = list(map(int, input().split()))
    C.append(_c)
    D.append(_d)
    edges2[_c].append(_d)
    edges2[_d].append(_c)

i, blocked = 1, 0
for b in edges2[1]:
    if uf.is_same_group(i, b):
        blocked += 1
print(uf.count(i) - 1 - len(edges1[i]) - blocked, end='')

for i in range(2, N + 1):
    print(' ', end='')
    blocked = 0
    for b in edges2[i]:
        if uf.is_same_group(i, b):
            blocked += 1
    print(uf.count(i) - 1 - len(edges1[i]) - blocked, end='')
print()

Solution (Python):
from collections import deque
n, m, k =map(int, input().split())


fd = dict()
directcount = [0] * n
visited = [[-1, -1] for i in range(n)]
q = deque(list())
g = []
for _ in range(n):
    g.append(deque(list()))


for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)
    directcount[a] += 1
    directcount[b] += 1
    fd[200000 * a + b] = True
    fd[200000 * b + a] = True

colorcount = [-1] * n

for i in range(n):
    q.append(i)
    color = i
    cnt = 1
    while len(q) > 0:
        
        nextnode = q.popleft() 
        if visited[nextnode][0] != -1:
            continue
        visited[nextnode] = [color, cnt]
        q.extend(g[nextnode]) 
        cnt += 1
    colorcount[color]  = cnt - 1









res = [[visited[i][0], colorcount[visited[i][0]]] for i in range(n)]


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

output = []
for i in range(n):
    output.append(res[i][1] - directcount[i] - 1)

print(" ".join(list(map(lambda x: str(x), output))))

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 isSameGroup(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()}
 
    def size(self, x):
        return -self.root[self.Find_Root(x)]
 
 
n, m, k = map(int, input().split())
 
uf = UnionFind(n)
directcount = [0] * n
 
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    directcount[a] += 1
    directcount[b] += 1
    uf.Unite(a, b)
 
res = []
for _ in range(n):
    res.append( [0, -1] )
ures = []
 
for i in range(n):
    res[i][0] = uf.size(i) - directcount[i] -1
    res[i][1] = uf.Find_Root(i)

 
 
for i in range(k):
    c, d = map(int, input().split())
    c -= 1
    d -= 1
    if res[c][1] == res[d][1]:
        res[c][0] -= 1
        res[d][0] -= 1
 
 
print(" ".join(list(map(lambda x: str(x[0]), res))))

Solution (Python):
from collections import deque


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

g = []

for _ in range(n):
    g.append(deque(list()))


bd = dict()
fd = dict()

directcount = [0] * n


for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)
    directcount[a] += 1
    directcount[b] += 1
    fd[200000 * a + b] = True
    fd[200000 * b + a] = True

visited = [[-1, -1] for i in range(n)]
q = deque(list())

for i in range(n):
    q.append(i)
    color = i
    cnt = 1
    while len(q) > 0:
        
        nextnode = q.popleft() 
        
        if visited[nextnode][0] != -1:
            
            continue
        visited[nextnode] = [color, cnt]
        q.extend(g[nextnode]) 
        cnt += 1

colorcount = [-1] * n

for i in range(n):
    colorcount[visited[i][0]] = max(colorcount[visited[i][0]], visited[i][1])





res = [[visited[i][0], colorcount[visited[i][0]]] for i in range(n)]


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

output = []
for i in range(n):
    output.append(res[i][1] - directcount[i] - 1)

print(" ".join(list(map(lambda x: str(x), output))))

Solution (Python):
import sys
input=sys.stdin.readline
class UnionFind():
  def __init__(self,n):
    self.n=n
    self.parent=list(range(n))
    self.size=[1]*n
    
  def find(self,x):
    if self.parent[x]==x:
      return x
    else:
      self.parent[x]=self.find(self.parent[x])
      return self.parent[x]
  def union(self,x,y):
    x=self.find(x)
    y=self.find(y)
    if x==y:
      return
    else:
      if self.size[x]>=self.size[y]:
        self.parent[y]=x
        self.size[x]+=self.size[y]
      else:
        self.parent[x]=y
        self.size[y]+=self.size[x]
  def cnt(self,x):
    return self.size[self.find(x)]
def main():
  n,m,k=map(int,input().split())
  u=UnionFind(n)
  ans=[0]*n
  for _ in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    u.union(a,b)
    ans[a]-=1
    ans[b]-=1
  for _ in range(k):
    c,d=map(int,input().split())
    c-=1
    d-=1
    if u.find(c)==u.find(d):
      ans[c]-=1
      ans[d]-=1
  for i in range(n):
    ans[i]+=u.cnt(i)-1
  print(" ".join(map(str,ans)))
main()

Solution (Python):
import sys

class UnionFind():
  def __init__(self,n):
    self.n=n
    self.parent=list(range(n))
    self.size=[1]*n
    
  def find(self,x):
    if self.parent[x]==x:
      return x
    else:
      self.parent[x]=self.find(self.parent[x])
      return self.parent[x]
  def union(self,x,y):
    x=self.find(x)
    y=self.find(y)
    if x==y:
      return
    else:
      if self.size[x]>=self.size[y]:
        self.parent[y]=x
        self.size[x]+=self.size[y]
      else:
        self.parent[x]=y
        self.size[y]+=self.size[x]
  def cnt(self,x):
    return self.size[self.find(x)]
def main():
  n,m,k=map(int,input().split())
  u=UnionFind(n)
  ans=[0]*n
  for _ in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    u.union(a,b)
    ans[a]-=1
    ans[b]-=1
  for _ in range(k):
    c,d=map(int,input().split())
    c-=1
    d-=1
    if u.find(c)==u.find(d):
      ans[c]-=1
      ans[d]-=1
  for i in range(n):
    ans[i]+=u.cnt(i)-1
  print(" ".join(map(str,ans)))
main()

Solution (Python):
from collections import defaultdict
class UnionFind:
    def __init__(self, n=0):
        self.d = [-1 for _ in range(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]: 
            t = x
            x = y
            y = t
        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)]
    

def main():
    N, M, K = map(int, input().split())
    uf = UnionFind(N)

    deg = [0 for _ in range(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)
    

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

    ret = []
    for i in range(N):
        ans = uf.size(i) - 1 - deg[i]
        for u in to[i]:
            if uf.same(i, u): ans -= 1
        ret.append(str(ans))

    print(' '.join(ret))


main()

Solution (Python):

class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parent = [-1 for _ in range(n)]
  def find(self, x):
    if self.parent[x] < 0:
      return x
    else:
      self.parent[x] = self.find(self.parent[x])
      return self.parent[x]
  def unite(self, x, y):
    x, y = self.find(x), self.find(y)
    if x == y:
      return False
    else:
      if self.size(x) < self.size(y):
        x, y = y, x
      self.parent[x] += self.parent[y]
      self.parent[y] = x
      return True
 
  def same(self, x, y):
    return self.find(x) == self.find(y)
  def size(self, x):
    x = self.find(x)
    return -self.parent[x]
  def is_root(self, x):
    return self.parent[x] < 0
 
  def members(self, x):
    root = self.find(x)
    return [i for i in range(self.n) if self.find(i) == root]

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

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) 

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N, M, K = LI()
AB = []
CD = []
for i in range(M):
    a,b = LI()
    a -= 1
    b -= 1
    AB.append([a,b])
for k in range(K):
    c, d = LI()
    c -= 1
    d -= 1
    CD.append([c,d])

direct_friend = {}
blocked = {}
relation = [[] for i in range(N)]
for i in range(N):
    direct_friend[i] = []
    blocked[i] = []
for i in range(M):
    a,b = AB[i]
    direct_friend[a].append(b)
    direct_friend[b].append(a)
for i in range(K):
    c,d = CD[i]
    blocked[c].append(d)
    blocked[d].append(c)

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

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

u = UnionFind(N)
for a,b in AB:
    u.Unite(a, b)

minus_cnt = [0 for i in range(N)]
for a,b in AB:
    minus_cnt[a] += 1
    minus_cnt[b] += 1


for c, d in CD:
    if u.isSameGroup(c,d):
        minus_cnt[c] += 1
        minus_cnt[d] += 1
for i in range(N):
    print(u.Count(i) - 1 - minus_cnt[i], end = " ")

print("")

"""
direct_friend = {}
blocked = {}
relation = [[] for i in range(N)]
for i in range(N):
    direct_friend[i] = []
    blocked[i] = []
for i in range(M):
    a,b = AB[i]
    direct_friend[a].append(b)
    direct_friend[b].append(a)
for i in range(K):
    c,d = CD[i]
    blocked[c].append(d)
    blocked[d].append(c)

def dfs(node, p, cluster):
    cluster.append(node)
    if len(direct_friend[node]) == 1:
        return cluster
    for new_node in direct_friend[node]:
        if new_node == p:continue
        elif new_node in cluster:continue
        else:
            return dfs(new_node, node, cluster)

for i in range(N):
    if len(relation[i]) == 0:
        cluster = dfs(i, -1, [])
        
        if cluster == None:
            relation[i] = []
        else:   
            for j in cluster:
                relation[j] = cluster





for i in range(N):
    blocked[i] = set(blocked[i])
    direct_friend[i] = set(direct_friend[i])




ans = []
for n in range(N):
    ans.append(len(set(relation[n]) - direct_friend[n] - blocked[n] - set([n])))

for a in ans:
    print(a, end = " ")
print("")

"""

Solution (Python):
class UnionFind():
    """
    https://note.nkmk.me/python-union-find/
    DFSの上位互換と考えて良い
    ２要素x, yがpath-connectedかどうかをlogオーダーで判定する（螺旋本の14.1節参照）
    さらに連結成分の要素数がO(1)で取得可能なように改造してある
    """
    def __init__(self, n):
        """
        要素数をnとして、各ノードを0,1,...,(n-1)の番号で管理する
        parentsは各ノードの属する木の根を表す
        ただし根ノードのparentには(その木のノード数)*(-1)を格納する
        """
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        """
        xの属する木の根を返す
        このとき同時に経路圧縮して、探索途中のノードを全て根に繋ぎ直す
        """
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        """
        x, yのそれぞれ属する木Tx, Tyの根同士を繋ぐ
        このとき木の要素数が小さい方を大きい方に繋ぐ（rankではなくsizeを用いる）
        """
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

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

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

    def size(self, x):
        """
        xの属する木の要素数を返す
        根の親を要素数の(-1)倍で定めておいたおかげでO(1)で取得可能
        """
        return -self.parents[self.find(x)]

    def same(self, x, y):
        """
        xとyがpath-connectedかを判定する
        """
        return self.find(x) == self.find(y)

    def members(self, x):
        """
        xの属する木の要素を列挙する
        """
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        """
        連結成分の代表元のリストを返す
        """
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        """
        連結成分の個数を返す
        """
        return len(self.roots())

    def all_group_members(self):
         """
         連結成分およびそれぞれの代表元をまとめた辞書を返す
         代表元がキーになってる
         """
         return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        """
        連結成分およびその代表元を出力
        """
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


"""
ここから本問の解答
"""

N, M, K = map(int, input().split())
uf = UnionFind(N)
friend_num = [0] * N
for _ in range(M):
    a, b = map(int, input().split())
    uf.union(a-1, b-1)
    friend_num[a-1] += 1
    friend_num[b-1] += 1
block = [[] for _ in range(N)]
for _ in range(K):
    c, d = map(int, input().split())
    block[c-1].append(d-1)
    block[d-1].append(c-1)

ans = []
for i in range(N):
    num = uf.size(i) - friend_num[i] - 1
    for j in block[i]:
        if uf.same(i, j):
            num -= 1
    ans.append(num)
print(" ".join(map(str, ans)))

Solution (Python):
from sys import setrecursionlimit
setrecursionlimit(2 * 10 ** 9)
 
N,M,K = map(int, input().split())

friends = {i: set() for i in range(N)}
blocks = {i: set() for i in range(N)}

for _ in range(M):
  a,b = map(int, input().split())
  a-=1;b-=1
  friends[a].add(b)
  friends[b].add(a)
for _ in range(K):
  a,b = map(int, input().split())
  a-=1;b-=1
  blocks[a].add(b)
  blocks[b].add(a)

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

def DFS(u):
  if visited[u]:
    return
  visited[u] = True
  for v in friends[u]:
    s.add(v)
    DFS(v)

for u in range(N):
  if not visited[u]:
    s = set()
    DFS(u)
    l = len(s)
    for i in s:
      ans[i] += l-1
      ans[i] -= len(blocks[i].intersection(s))
      ans[i] -= len(friends[i].intersection(s))
print(*ans)

Solution (Python):


class UnionFind():
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        if self.par[x] != x:
            self.par[x] = self.find(self.par[x])
        return self.par[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.par[xroot] = yroot
            self.size[yroot] = self.size[xroot] + self.size[yroot]
        else:
            
            self.par[yroot] = xroot
            self.size[xroot] = self.size[xroot] + self.size[yroot]

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


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

    friend_edge = []
    for _ in range(m):
        friend_edge.append(tuple(map(int, input().split())))

    block_edge = []
    for _ in range(k):
        block_edge.append(tuple(map(int, input().split())))

    return n, friend_edge, block_edge


def submit():
    n, friend_edge, block_edge = read_input()

    
    uf = UnionFind(n)
    for a, b in friend_edge:
        uf.unite(a - 1, b - 1)

    
    
    remove_dict = {i : 0 for i in range(n)}
    for c, d in block_edge:
        if uf.same(c - 1, d - 1):
            remove_dict[c - 1] += 1
            remove_dict[d - 1] += 1
        
    
    for a, b in friend_edge:
        remove_dict[a - 1] += 1
        remove_dict[b - 1] += 1

    
    result = []
    for i in range(n):
        target_size = uf.size[uf.find(i)]
        result.append(target_size - remove_dict[i] - 1)

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


if __name__ == "__main__":
    submit()