Problem:
 Score : 400 points    Problem Statement An SNS has N users - User 1 , User 2 , \cdots , User N .  Between these N users, there are some relationships - M  friendships and K  blockships .  For each i = 1, 2, \cdots, M , there is a bidirectional friendship between User A_i and User B_i .  For each i = 1, 2, \cdots, K , there is a bidirectional blockship between User C_i and User D_i .  We define User a to be a friend candidate for User b when all of the following four conditions are satisfied:   a \neq b .  There is not a friendship between User a and User b .  There is not a blockship between User a and User b .  There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a , c_L = b , and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1 .   For each user i = 1, 2, ... N , how many friend candidates does it have?      Constraints  All values in input are integers.  2 ≤ N ≤ 10^5  0 \leq M \leq 10^5  0 \leq K \leq 10^5  1 \leq A_i, B_i \leq N  A_i \neq B_i  1 \leq C_i, D_i \leq N  C_i \neq D_i  (A_i, B_i) \neq (A_j, B_j) (i \neq j)  (A_i, B_i) \neq (B_j, A_j)  (C_i, D_i) \neq (C_j, D_j) (i \neq j)  (C_i, D_i) \neq (D_j, C_j)  (A_i, B_i) \neq (C_j, D_j)  (A_i, B_i) \neq (D_j, C_j)         Input Input is given from Standard Input in the following format:  N  M  K  A_1  B_1  \vdots  A_M  B_M  C_1  D_1  \vdots  C_K  D_K       Output Print the answers in order, with space in between.        Sample Input 1 4 4 1
2 1
1 3
3 2
3 4
4 1      Sample Output 1 0 1 0 1  There is a friendship between User 2 and 3 , and between 3 and 4 . Also, there is no friendship or blockship between User 2 and 4 . Thus, User 4 is a friend candidate for User 2 .  However, neither User 1 or 3 is a friend candidate for User 2 , so User 2 has one friend candidate.       Sample Input 2 5 10 0
1 2
1 3
1 4
1 5
3 2
2 4
2 5
4 3
5 3
4 5      Sample Output 2 0 0 0 0 0  Everyone is a friend of everyone else and has no friend candidate.       Sample Input 3 10 9 3
10 1
6 7
8 2
2 5
8 4
7 3
10 9
6 4
5 8
2 6
7 5
3 1      Sample Output 3 1 3 5 4 3 3 3 3 1 0

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

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

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

	if pa != pb:
		if sizes[pa] <= sizes[pb]: pa,pb = pb,pa
		parent[pb] = pa
		sizes[pa] += sizes[pb]
		
for _ in range(k):
	c,d = map(int,sys.stdin.readline().split())
	pc,pd = f(parent, c), f(parent, d)
	if (pc == pd):
		hd[c] += 1
		hd[d] += 1

print ' '.join([str(sizes[f(parent,u)] - hd[u])  for u in range(1, n+1)])

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

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

for a,b in [map(int,sys.stdin.readline().split()) for _ in range(m)]:

	pa,pb = f(parent, a), f(parent, b)
	hd[a] +=1
	hd[b] +=1

	if pa != pb:
		if sizes[pa] <= sizes[pb]: pa,pb = pb,pa
		parent[pb] = pa
		sizes[pa] += sizes[pb]
		

for c,d in [map(int,sys.stdin.readline().split()) for _ in range(k)]:
	pc,pd = f(parent, c), f(parent, d)
	if (pc == pd):
		hd[c] += 1
		hd[d] += 1

print ' '.join([str(sizes[f(parent,u)] - hd[u])  for u in range(1, n+1)])

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

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

for a,b in [map(int,sys.stdin.readline().split()) for _ in range(m)]:

	pa,pb = f(parent, a), f(parent, b)
	hd[a] +=1
	hd[b] +=1

	if pa != pb:
		if sizes[pa] >= sizes[pb]:
			parent[pb] = pa
			sizes[pa] += sizes[pb]
		else:
			parent[pa] = pb
			sizes[pb] += sizes[pa]

for c,d in [map(int,sys.stdin.readline().split()) for _ in range(k)]:
	pc,pd = f(parent, c), f(parent, d)
	if (pc == pd):
		hd[c] += 1
		hd[d] += 1

print ' '.join([str(sizes[f(parent,u)] - hd[u])  for u in range(1, n+1)])

Solution (Python):
import collections

n,m,k = map(int,raw_input().split(' '))


parent = range(0, n+1)
sizes = [1] * (n + 1)
hd = [1] * (n + 1) 

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

for a,b in [map(int, raw_input().split(' ')) for _ in range(m)]:

	pa,pb = f(parent, a), f(parent, b)
	hd[a] +=1
	hd[b] +=1

	if pa != pb:
		if sizes[pa] >= sizes[pb]:
			parent[pb] = pa
			sizes[pa] += sizes[pb]
		else:
			parent[pa] = pb
			sizes[pb] += sizes[pa]

for c,d in [map(int, raw_input().split(' ')) for _ in range(k)]:
	pc,pd = f(parent, c), f(parent, d)
	if (pc == pd):
		hd[c] += 1
		hd[d] += 1

print ' '.join([str(sizes[f(parent,u)] - hd[u])  for u in range(1, n+1)])

Solution (Python):
import collections

n,m,k = map(int,raw_input().split(' '))

friendships = [map(int, raw_input().split(' ')) for _ in range(m)]
disses = [map(int, raw_input().split(' ')) for _ in range(k)]

parent = [i for i in range(0, n+1)]
sizes = [1 for i in range(0, n+1)]
hd = [1 for i in range(0, n + 1)]


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

for a,b in friendships:

	pa,pb = f(parent, a), f(parent, b)
	hd[a] +=1
	hd[b] +=1

	if pa != pb:
		if sizes[pa] >= sizes[pb]:
			parent[pb] = pa
			sizes[pa] += sizes[pb]
		else:
			parent[pa] = pb
			sizes[pb] += sizes[pa]

for c,d in disses:
	pc,pd = f(parent, c), f(parent, d)
	if (pc == pd):
		hd[c] += 1
		hd[d] += 1

print ' '.join([str(sizes[f(parent,u)] - hd[u])  for u in range(1, n+1)])

Solution (Python):
import collections

n,m,k = map(int,raw_input().split(' '))

friendships = [map(int, raw_input().split(' ')) for _ in range(m)]
disses = [map(int, raw_input().split(' ')) for _ in range(k)]

parent = [i for i in range(0, n+1)]
sizes = [1 for i in range(0, n+1)]

hd = collections.Counter()
adj = collections.defaultdict(set)

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

for a,b in friendships:

	pa,pb = f(parent, a), f(parent, b)
	
	adj[a].add(b)
	adj[b].add(a)

	if pa != pb:
		if sizes[pa] >= sizes[pb]:
			parent[pb] = pa
			sizes[pa] += sizes[pb]
		else:
			parent[pa] = pb
			sizes[pb] += sizes[pa]

for c,d in disses:
	pc,pd = f(parent, c), f(parent, d)
	if d not in adj[c] and (pc == pd):
		hd[c] += 1
		hd[d] += 1

print ' '.join([str(sizes[f(parent,u)] - len(adj[u]) - hd[u] - 1)  for u in range(1, n+1)])

Solution (Python):
import collections

n,m,k = map(int,raw_input().split(' '))

friendships = [map(int, raw_input().split(' ')) for _ in range(m)]
disses = [map(int, raw_input().split(' ')) for _ in range(k)]

parent = {i:i for i in range(0, n+1)}
sizes = {i:1 for i in range(0, n+1)}

hd = collections.Counter()

adj = collections.defaultdict(set)

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

for a,b in friendships:

	pa,pb = f(parent, a), f(parent, b)
	
	adj[a].add(b)
	adj[b].add(a)

	if pa != pb:
		if sizes[pa] >= sizes[pb]:
			parent[pb] = pa
			sizes[pa] += sizes[pb]
		else:
			parent[pa] = pb
			sizes[pb] += sizes[pa]

for c,d in disses:
	pc,pd = f(parent, c), f(parent, d)
	if d not in adj[c] and (pc == pd):
		hd[c] += 1
		hd[d] += 1

print ' '.join([str(sizes[f(parent,u)] - len(adj[u]) - hd[u] - 1)  for u in range(1, n+1)])

Solution (Python):
import collections

n,m,k = map(int,raw_input().split(' '))

friendships = [map(int, raw_input().split(' ')) for _ in range(m)]
disses = [map(int, raw_input().split(' ')) for _ in range(k)]

parent = {i:i for i in range(0, n+1)}
sizes = {i:1 for i in range(0, n+1)}

hd = collections.Counter()

adj = collections.defaultdict(set)

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

for a,b in friendships:
	if a == b: continue

	pa,pb = f(parent, a), f(parent, b)
	
	adj[a].add(b)
	adj[b].add(a)

	if pa != pb:
		if sizes[pa] >= sizes[pb]:
			parent[pb] = pa
			sizes[pa] += sizes[pb]
		else:
			parent[pa] = pb
			sizes[pb] += sizes[pa]

for c,d in disses:
	pc,pd = f(parent, c), f(parent, d)
	if (pc == pd):
		hd[c] += 1
		hd[d] += 1
"""
hd[u] = k
u has k disses in its connected component
"""

print ' '.join([str(sizes[f(parent,u)] - len(adj[u]) - hd[u] - 1)  for u in range(1, n+1)])

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

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

N, M, K = map(int, input().split())
friend = UnionFind(N+1)
nocount = [[] for _ in range(N+1)]
ans = [0]*N
for i in range(M):
  a, b = map(int, input().split())
  friend.union(a,b)
  nocount[a].append(b)
  nocount[b].append(a)
for i in range(K):
  a, b = map(int, input().split())
  nocount[a].append(b)
  nocount[b].append(a)
for i in range(1, N+1):
  ans[i-1] = friend.size(i) -1
  for j in nocount[i]:
    if friend.same(i,j):
      ans[i-1] -= 1
print(*ans)

Solution (Python):






import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr


def lcm(a, b):
    return a * b // gcd (a, b)





N,M,K = inputIL()

friend = [[] for _ in range(N)]
friend_edges = []
for _ in range(M):
  a, b = inputIL()
  friend_edges.append((a-1, b-1))
for a, b in friend_edges:
  friend[a].append(b)
  friend[b].append(a)
  
block = [[] for _ in range(N)]
block_edges = []
for _ in range(K):
  a, b = inputIL()
  block_edges.append((a-1, b-1))
for a, b in block_edges:
  block[a].append(b)
  block[b].append(a)

  
cluster = [None for i in range(N)]
count = []

n = -1
for v in range(N):
  if cluster[v] == None:
    n += 1
    q = deque([v])
    cluster[v] = n
    c = 1
    while q:
      i = q.popleft()
      for j in friend[i]:
        if cluster[j] == None:
          cluster[j] = n
          c += 1
          q.append(j)
    count.append(c)

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

for a, b in friend_edges:
  if cluster[a]==cluster[b]:
    ans[a] -= 1
    ans[b] -= 1

for a, b in block_edges:
  if cluster[a]==cluster[b]:
    ans[a] -= 1
    ans[b] -= 1
  

print(*ans,sep=" ")

Solution (Python):
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter

from functools import lru_cache

sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    '''
    一つの整数
    '''
    return int(input())
def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))

class UnionFind():
    def __init__(self, n):
        """
        Parameters
        ----------
        n:int
            the number of node
        """
        self.par = [-1] * n 

    def find(self, x):
        """
        Parameters
        ----------
        x:int
            target node

        Return
        ----------
        res:int
            root node
        """
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

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

    def is_same(self, x, y):
        return self.find(x) == self.find(y)
    
    def size(self, x):
        '''
        Parameters
        ----------
        x:int
            target node
        
        Return
        ----------
        x:int
            size of  group  to which belongs
        '''
        return - self.par[self.find(x)]
        

n, m, k = inpl()
dame = collections.defaultdict(set)
uf = UnionFind(n)
ans=[0]*n
for i in range(m):
    a, b = inpl()
    a, b = a - 1, b - 1
    dame[a].add(b)
    dame[b].add(a)
    uf.union(a,b)
for i in range(k):
    c, d = inpl()
    c, d = c - 1, d - 1
    if uf.is_same(c,d):
        dame[c].add(d)
        dame[d].add(c)
for i in range(n):
    ans[i] = uf.size(i) - len(dame[i]) - 1
    
print(*ans)

'''

'''

Solution (Python):
import sys
sys.setrecursionlimit(10**5)

n,m,k=map(int,input().split())
fr=[0 for _ in range(n)]
frl=[[] for i in range(n)]
frlist=[]
for i in range(m):
    a,b=map(int,input().split())
    frl[a-1].append(b)
    frl[b-1].append(a)
    frlist.append([a,b])

treelist=[]
hitobito=set()

def saiki(c,tmpi):
    global hitobito
    global tmpset
    global trbl
    
    if frl[c-1] == []:
        hitobito.add(c)
        tmpset.add(c)
        trbl[c-1]=tmpi
    
    for tsugi in frl[c-1]:
        if not tsugi in hitobito:
            hitobito.add(tsugi)
            tmpset.add(tsugi)
            trbl[tsugi-1]=tmpi
            saiki(tsugi,tmpi)

index=0
trbl=[None for _ in range(n)]
for i in range(n):
    tmpset=set()
    saiki(i+1,index)
    if not tmpset == set():
        treelist.append(tmpset)
        index+=1

bl=[0 for _ in range(n)]
bll=[[] for i in range(n)]
bllist=[]
for i in range(k):
    a,b=map(int,input().split())
    bll[a-1].append(b)
    bll[b-1].append(a)
    bllist.append([a,b])

for fre in frlist:
    if trbl[fre[0]-1] == trbl[fre[1]-1]:
        fr[fre[0]-1]=fr[fre[0]-1]+1
        fr[fre[1]-1]=fr[fre[1]-1]+1

for blo in bllist:
    if trbl[blo[0]-1] == trbl[blo[1]-1]:
        bl[blo[0]-1]=bl[blo[0]-1]+1
        bl[blo[1]-1]=bl[blo[1]-1]+1

output=[]
for i in range(n):
    tmpsum=fr[i]+bl[i]
    output.extend([str(len(treelist[trbl[i]])-tmpsum-1)," "])

print("".join(output))

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 __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=[0]*n
for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    friend[a]+=1
    friend[b]+=1
    uf.union(a,b)

block=[0]*n
for i in range(k):
    c,d=map(int,input().split())
    c-=1
    d-=1
    if uf.same(c,d):
        block[c]+=1
        block[d]+=1

ans=[0]*n
for i in range(n):
    ans[i]=uf.size(i)-friend[i]-block[i]-1

print(*ans)

Solution (Python):
N, M, K = map(int, input().split())
INF = 10**9

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


union_find = UnionFind(N)
friend_num_list = [0]*N
block_num_list = [0]*N

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

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

ans_list = [0]*N
for i in range(N):
    ans = union_find.size(i) - friend_num_list[i] - block_num_list[i] - 1
    ans_list[i] = ans
print(*ans_list)

Solution (Python):
import sys
input = sys.stdin.readline
def main():
  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)]
  gf=[[]for _ in range(n)]
  for a,b in ab:
    gf[a-1].append(b-1)
    gf[b-1].append(a-1)
  gb=[[]for _ in range(n)]
  for c,d in cd:
    gb[c-1].append(d-1)
    gb[d-1].append(c-1)
  seen=[0]*n
  ans=[0]*n
  for i in range(n):
    c=set([i])
    if seen[i]==0:
      todo=[i]
      while todo:
        e=todo.pop()
        l=gf[e]
        for li in l:
          if seen[li]==0:
            todo.append(li)
            seen[li]=1
            c.add(li)
      base=len(c)-1
      for ci in c:
        ans[ci]=base
        for fb in gb[ci]+gf[ci]:
          if fb in c:
            ans[ci]-=1
  print(' '.join(map(str,ans)))
if __name__=='__main__':
  main()

Solution (Python):
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self):
        return len(self.roots())
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M, K = map(int, input().split())
uf = UnionFind(N)
cnt = [0]*(N+1)
cnt2 = [[] for _ in range(N+1)]
ans = [0]*N
for i in range(M):
    A, B = map(int, input().split())
    uf.union(A-1,B-1)
    cnt[A] += 1
    cnt[B] += 1
for i in range(K):
    C, D = map(int, input().split())
    cnt2[D].append(C)
    cnt2[C].append(D)
for i in range(N):
    tmp = 0
    for k in cnt2[i+1]:
        if uf.same(k-1,i):
            tmp += 1
    ans[i] = uf.size(i)-1-cnt[i+1]-tmp
print(*ans)

Solution (Python):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
from collections import defaultdict
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import numpy as np










N,M,K = map(int,input().split())
fr = [[] for _ in range(N)]
br = [[] for _ in range(N)]
for _ in range(M):
    a,b = map(int,input().split())
    fr[a-1].append(b-1)
    fr[b-1].append(a-1)
for _ in range(K):
    c,d = map(int,input().split())
    br[c-1].append(d-1)
    br[d-1].append(c-1)
used = [-1]*N 
renketu = []
index = 0
def dfs(fr,cur,parent,index,li):
    children = fr[cur]
    for chi in children:
        if chi == parent or used[chi] != -1:
            continue
        used[chi] = index
        li.append(chi)
        dfs(fr,chi,cur,index,li)
for i in range(N):
    if used[i] != -1:
        continue
    li = [i]
    used[i] = index
    dfs(fr,i,-1,index,li)
    index += 1
    renketu.append(li)
ans = [0]*N
for i in range(N):
    ans[i] = len(renketu[used[i]])-1
for i in range(N):
    li1 = fr[i]
    li2 = br[i]
    for j1 in li1:
        if i < j1:
            if used[i] == used[j1]:
                ans[i] -= 1
                ans[j1] -= 1
    for j2 in li2:
        if i < j2:
            if used[i] == used[j2]:
                ans[i] -= 1
                ans[j2] -= 1
print(*ans)

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

user=[0 for i in range(N+1)]
graph_ab=[[] for i in range(N+1)]
graph_cd=[[] for i in range(N+1)]
visited=[0 for i in range(N+1)]
for i in range(M):
    a,b=AB[i]
    graph_ab[a].append(b)
    graph_ab[b].append(a)
time=0
for j in range(1,N+1):
    if visited[j]==0:
        stack=deque([j])
        time+=1
        visited[j]=time
        while stack:
            x=stack.popleft()
            for i in graph_ab[x]:
                if visited[i]==0:
                    visited[i]=time
                    stack.append(i)

counter=Counter(visited) 
for i in range(K):
    c,d=CD[i]
    if visited[c]==visited[d]:
        graph_cd[c].append(d)
        graph_cd[d].append(c)

for i in range(1,N+1):
    user[i]=counter[visited[i]]-len(graph_ab[i])-len(graph_cd[i])-1

del user[0]
print(*user)

Solution (Python):

import copy
import itertools
import sys
sys.setrecursionlimit(10**5)
def addp(a, i, j):
    tmp1 = searchp(a, i)
    tmp2 = searchp(a, j)
    if(tmp1 != tmp2):
        a[tmp2][0] = tmp1
        a[tmp1][1] += a[tmp2][1]

def searchp(a, i):
    if(a[i][0]==i):
        return i
    else:
        tmp = searchp(a, a[i][0])
        a[i][0] = tmp
        return tmp
n, m, k = map(int, input().split())

clist = [[1] * 2 for i in range(n)]

for i in range(n):
    clist[i][0] = i
flist = [[0] * 2 for i in range(m)]
blist = [[0] * 2 for i in range(k)]
for i in range(m):
    flist[i] = list(map(int, input().split()))
for i in range(k):
    blist[i] = list(map(int, input().split()))
for i in range(m):
    addp(clist, flist[i][0]-1, flist[i][1]-1)
for i in range(n):
    if(clist[i][0] != i):
        tmp = searchp(clist, i)
        clist[i][0] = tmp
        clist[i][1] = clist[tmp][1]
for i in range(m):
    if(searchp(clist, flist[i][0]-1) == searchp(clist, flist[i][1]-1)):
        clist[flist[i][0]-1][1] -= 1
        clist[flist[i][1]-1][1] -= 1
for i in range(k):
    if(searchp(clist, blist[i][0]-1) == searchp(clist, blist[i][1]-1)):
        clist[blist[i][0]-1][1] -= 1
        clist[blist[i][1]-1][1] -= 1
for i in range(n):
    print(clist[i][1]-1)

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())
retu_n=[0]*N
block_n=[0]*N
uf = UnionFind(N)


for m in range(M):
  a,b=map(int,input().split())
  retu_n[a-1] +=1
  retu_n[b-1] +=1
  uf.union(a-1,b-1)
  
  
for k in range(K):
  c,d=map(int,input().split())
  if uf.same(c-1, d-1):
    block_n[c-1] += 1
    block_n[d-1] += 1
    
  
for n in range(N):
  print(uf.size(n)-retu_n[n]-block_n[n]-1, end=" ")

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


N,M,K=map(int,input().split())
retu_n=[0]*N
block_n=[0]*N
uf = UnionFind(N)

for m in range(M):
  a,b=map(int,input().split())
  retu_n[a-1] +=1
  retu_n[b-1] +=1
  uf.unite(a,b)
  
  
for k in range(K):
  c,d=map(int,input().split())
  if uf.same(c, d):
    block_n[c-1] += 1
    block_n[d-1] += 1
    
  
for n in range(N):
  print(uf.size(n+1)-retu_n[n]-block_n[n]-1, end=" ")

Solution (Python):
import collections
import itertools
import operator


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


N,M,K=map(int,input().split())
retu_n=[0]*N
block_n=[0]*N
uf = UnionFind(N)

for m in range(M):
  a,b=map(int,input().split())
  retu_n[a-1] +=1
  retu_n[b-1] +=1
  uf.unite(a,b)
  
  
for k in range(K):
  c,d=map(int,input().split())
  if uf.same(c, d):
    block_n[c-1] += 1
    block_n[d-1] += 1
    
  
for n in range(N):
  print(uf.size(n+1)-retu_n[n]-block_n[n]-1, end=" ")

Solution (Python):
import sys
from collections import deque

input = sys.stdin.readline


def dfs(G, comp_id, comp_cnt):
    i = 0
    cnt = 0
    for v in range(len(G)):
        if comp_id[v] != -1:
            continue
        comp_id[v] = i
        cnt += 1
        stack = deque([v])
        while stack:
            v = stack.pop()
            for c in G[v]:
                if comp_id[c] != -1:
                    continue
                comp_id[c] = i
                cnt += 1
                stack.append(c)
        comp_cnt.append(cnt)
        cnt = 0
        i += 1


def main():
    N, M, K = map(int, input().split())
    G = [[] for _ in range(N)]
    for _ in range(M):
        A, B = map(int, input().split())
        A -= 1
        B -= 1
        G[A].append(B)
        G[B].append(A)
    B = [[] for _ in range(N)]
    for _ in range(K):
        C, D = map(int, input().split())
        C -= 1
        D -= 1
        B[C].append(D)
        B[D].append(C)

    
    comp_id = [-1] * N
    comp_cnt = []
    dfs(G, comp_id, comp_cnt)

    ans = [-1] * N
    for i in range(N):
        c_id = comp_id[i]
        n_neighbor = len(G[i])
        n_block = len(B[i])
        for j in B[i]:
            if c_id != comp_id[j]:
                n_block -= 1
        ans[i] = comp_cnt[c_id] - 1 - n_neighbor - n_block
    print(*ans)


if __name__ == "__main__":
    main()