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



Sample input:
4 4 1
2 1
1 3
3 2
3 4
4 1


Sample output:
0 1 0 1

Submission status: Wrong Answer

Solution code:
import numpy as np
N,M,K = list(map(int,input().split()))
F = [[0]*N for i in range(N)]
B = [[0]*N for i in range(N)]
for i in range(M):
  R = list(map(int,input().split()))
  F[R[0]-1][R[1]-1] = 1
  F[R[1]-1][R[0]-1] = 1
f = [[0]*N for i in range(N)]
for p in range(N):
  f[p] = [j for j in range(N) if F[p][j] == 1]

for i in range(K):
  R = list(map(int,input().split()))
  B[R[0]-1][R[1]-1] = 1
  B[R[1]-1][R[0]-1] = 1
b = [[0]*N for i in range(N)]
for p in range(N):
  b[p] = [j for j in range(N) if B[p][j] == 1]

ANS = [[0]*N for i in range(N)]
for p in range(N):
  for i in f[p]:
      for j in f[i]:
        if (j not in f[p]+b[p]) and (j!=p):
          ANS[p][j] = 1

def rev(ANS):
  for p in range(N):
    for i in range(N):
      if ANS[p][i]==1:
        S = [j for j in range(N) if j in f[i]]
        S = [s for s in S if s not in f[p]] 
        for s in S:
          ANS[p][s] = 1
  return ANS

def cnt(ANS):
  ans = ''
  for a in ANS:
    ans += str(sum(a)) + ' '
  return ans[:-1]

ans = cnt(ANS)
temp = ''
while ans != temp:
  temp = cnt(ANS)
  ANS = rev(ANS)
  ans = cnt(ANS)

for p in range(N):
  for i in b[p]:
    ANS[p][i] = 0

ans = cnt(ANS)
print(ans)

Submission status: Wrong Answer

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

# DFSテンプレ、計算量=O(N+M)
# N:頂点の数
# M:辺の数

G = [[] for _ in range(N)]
# graphの入力
for _ in range(M):
    a,b = list(map(int,input().split()))
    G[a-1].append(b-1)
    G[b-1].append(a-1)
# print("G:",G)

KG = [[] for _ in range(N)]
# block graphの入力
for _ in range(K):
    a,b = list(map(int,input().split()))
    KG[a-1].append(b-1)
    KG[b-1].append(a-1)
# print("KG:",KG)

# ここまでエラーなし。

def dfs(G,v):
    # global l
    # nを訪問済みにする
    seen[v] = 1
    # l += 1
    # print(v+1)
    seenV.append(v)
    # vから行ける各頂点next_vについて
    for next_v in G[v]:
        if seen[next_v] == 1:
            continue
        else:
            dfs(G,next_v)

# Adj_size = [0]*N
# 全頂点を未訪問に初期化。
Adj = [[] for _ in range(N)]
seen = [0]*N
Y = []
for v in range(N):
    # l = 0
    seenV = []
    if seen[v] == 0:
        # dfs(G,v)
        pass
    
        # print("dfs done !!!")
    # print("v=",v+1,"seen:",seen)
    # print("l=",l)
    # print(seenV)
    
    for sv in seenV:
        Adj[sv] = seenV
    
    # print("Adj[",v,"] :",Adj[v])
    
    # 出力
    # y = Adj_size[v] - len(G[v])-1
    y = len(Adj[v]) - len(G[v]) - 1
    for k in KG[v]:
        if k in Adj[v]:
            y += -1
    # print("v=",v+1,"y=",y)
    Y.append(str(y))

# print("ADj",Adj)
# print("Y",Y)
# print("G",G)

print(" ".join(Y))

Submission status: Wrong Answer

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

# DFSテンプレ、計算量=O(N+M)
# N:頂点の数
# M:辺の数

G = [[] for _ in range(N)]
# graphの入力
for _ in range(M):
    a,b = list(map(int,input().split()))
    G[a-1].append(b-1)
    G[b-1].append(a-1)
# print("G:",G)

KG = [[] for _ in range(N)]
# block graphの入力
for _ in range(K):
    a,b = list(map(int,input().split()))
    KG[a-1].append(b-1)
    KG[b-1].append(a-1)
# print("KG:",KG)

"""
def dfs(G,v):
    # global l
    # nを訪問済みにする
    seen[v] = 1
    # l += 1
    # print(v+1)
    seenV.append(v)
    # vから行ける各頂点next_vについて
    for next_v in G[v]:
        if seen[next_v] == 1:
            continue
        else:
            dfs(G,next_v)

# Adj_size = [0]*N
# 全頂点を未訪問に初期化。
Adj = [0]*N
seen = [0]*N
Y = []
for v in range(N):
    # l = 0
    seenV = []
    if seen[v] == 0:
        dfs(G,v)
    
        # print("dfs done !!!")
    # print("v=",v+1,"seen:",seen)
    # print("l=",l)
    # print(seenV)
    
    for sv in seenV:
        # Adj_size[sv] = l
        Adj[sv] = seenV
    # print("Adj_size:",Adj_size)
    
    # 出力
    # y = Adj_size[v] - len(G[v])-1
    y = len(Adj[v]) - len(G[v])-1
    for k in KG[v]:
        if k in Adj[v]:
            y += -1
    # print("v=",v+1,"y=",y)
    Y.append(str(y))

# print("ADj",Adj)
# print("Y",Y)
# print("G",G)

print(" ".join(Y))
"""

Submission status: Wrong Answer

Solution code:
class UnionFind:
    """
    sizeによる実装
    """

    def __init__(self, N):
        self.parent = [i for i in range(N)]
        self.size = [1 for _ in range(N)]

    def find(self, x):
        """
        x: child
        ret-> node
        xのグループの代表を見つける
        """
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])

    def union(self, x, y):
        """
        union (x ,y)
        x,y: node
        ret->None
        """
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return
        if self.size[px] < self.size[py]:
            self.parent[px] = py
            self.size[py] += self.size[px]
        else:
            self.parent[py] = px
            self.size[px] += self.size[py]

    def same(self, x, y):
        """
        return true if x and y are in same group
        """
        return self.find(x) == self.find(y)

    def connectedNum(self, x):
        """
        return size of the group x belong to
        """
        return self.size[self.find(x)]

    def is_connected(self):
        """
        return true is all node is in one group
        """
        return self.connectedNum(0) == len(self.parent)


N, M, K = map(int, input().split())
F = [list(map(lambda x:int(x)-1, input().split())) for _ in range(M)]
B = [list(map(lambda x:int(x)-1, input().split())) for _ in range(K)]

B_set = [set() for _ in range(N)]
for a, b in B:
    B_set[a].add(b)
    B_set[b].add(a)
for a, b in F:
    B_set[a].add(b)
    B_set[b].add(a)

Un = UnionFind(N)
for a, b in F:
    Un.union(a, b)

ans = [0]*N
for i in range(N):
    ans[i] = Un.connectedNum(i) - len(B_set[i])-1
print(*ans)

Submission status: Wrong Answer

Solution code:
class UnionFind:
    def __init__(self, N):
        self.roots = list(range(N + 1))
        self.counter = [1] * (N + 1)

    def get_root(self, n):
        if self.roots[n] != n:
            self.roots[n] = self.get_root(self.roots[n])
        return self.roots[n]

    def union(self, a, b):
        a, b = sorted([self.get_root(a), self.get_root(b)])
        if a != b:
            self.roots[b] = a
            self.counter[a] += self.counter[b]
            self.counter[b] = 0

    def find(self, a, b):
        return self.get_root(a) == self.get_root(b)

    def count(self, x):
        return (self.counter[self.get_root(x)])

def resolve():
    N, M, K = [int(x) for x in input().split()]
    list = [[] for _ in range(N)]
    block = [[] for _ in range(N)]

    uf = UnionFind(N)

    for _ in range(M):
        A, B = [int(x)-1 for x in input().split()]
        list[A].append(B)
        list[B].append(A)
        uf.union(A,B)

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

    for i in range(N):
        ans = uf.count(i) - len(list[i]) - 1
        for j in block[i]:
            if uf.find(i ,j):
                ans -= 1

        print(ans, end=" ")

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO
import unittest

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 resolve():
    N, M, K = [int(x) for x in input().split()]
    global list, block, seen, osusume
    list = [[] for _ in range(N)]
    block = [[] for _ in range(N)]
    seen = [[False] * N for _ in range(N)]
    osusume = [[] for _ in range(N)]

    uf = UnionFind(N)
    ufblock = UnionFind(N)

    for _ in range(M):
        A, B = [int(x)-1 for x in input().split()]
        list[A].append(B)
        list[B].append(A)
        uf.union(A,B)

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

    for i in range(N):
        print(uf.size(i) - len(list[i]) - 1 - len(block[i]), end=" ")
resolve()

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
r=[[99999 for i in range(n)] for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  r[a-1][b-1]=1;r[b-1][a-1]=1
for i in range(k):
  c,d=map(int,input().split())
  r[c-1][d-1]=-999999;r[d-1][c-1]=-9999999
for i in range(n):
  r[i][i]=0
for k in range(n):
  for i in range(n):
    for j in range(n):
      if r[i][j] >=0 and r[i][k]>=0 and r[k][j]>=0: 
        r[i][j]=min(r[i][j],r[i][k]+r[k][j])
ans=[0 for i in range(n)]
for i in range(n):
  ans[i]=0
  for j in range(n):
    if 1<r[i][j] and r[i][j]<99999:
      ans[i]+=1
print(*ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import time

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

friend_dict = defaultdict(lambda:[])
block_dict = defaultdict(lambda:[])
root = {}
numroot = {}
next = 0

for i in range(M):
    s = input()
    a, b = s.split(" ")
    a = int(a) - 1
    b = int(b) - 1

    ab = a
    bb = b

    a = min(ab, bb)
    b = max(ab, bb)
    #print((a, b))

    for x, y in ((a, b), (b, a)):
        friend_dict[x].append(y)

    if b in root:
        root[a] = b
    else:
        root[b] = a

#print(root)

union = dict(zip(range(N), range(N)))
unionnum = defaultdict(lambda:1)
for before, rootnum in root.items():
    while rootnum in root:
        rootnum = root[rootnum]
    union[before] = rootnum
    unionnum[rootnum] += 1

#print(union)
#print(unionnum)

time.sleep(1)

result = []
for i in range(N):
    ret = unionnum[union[i]] -1

    #print(f"un={ret}")

    for friend in friend_dict[i]:
        if union[friend] == union[i]:
            ret -=1
    for block in block_dict[i]:
        if union[block] == union[i]:
            ret -=1
    result.append(ret)


#print(union)
print(" ".join([str(i) for i in result]))

Submission status: Wrong Answer

Solution code:

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

friend_list = []
block_list = []
root = {}
next = 0

for i in range(M):
    s = input()
    a, b = s.split(" ")
    a = int(a) - 1
    b = int(b) - 1

    ab = a
    bb = b

    a = min(ab, bb)
    b = max(ab, bb)
    print((a, b))

    friend_list.append((a, b))
    if b in root:
        root[a] = root[b]
    else:
        root[b] = a

union = []
for i in range(N):
    c_root = i
    while True:
        if c_root in root:
            c_root = root[c_root]
        else:
            union.append(c_root)
            break


for i in range(K):
    s = input()
    a, b = s.split(" ")
    a = int(a) - 1
    b = int(b) - 1
    block_list.append((a, b))


result = []
for i in range(N):
    ret = 0
    if union[i] is None:
        result.append(0)
        continue
    for j in range(N):
        if i == j:
            continue
        if union[i] != union[j]:
            continue
        if (i, j) in block_list:
            continue
        if (j, i) in block_list:
            continue
        if (i, j) in friend_list:
            continue
        if (j, i) in friend_list:
            continue
        ret += 1
    result.append(ret)

#print(union)
print(" ".join([str(i) for i in result]))

Submission status: Wrong Answer

Solution code:

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

friend_list = []
block_list = []
root = {}
next = 0

for i in range(M):
    s = input()
    a, b = s.split(" ")
    a = int(a) - 1
    b = int(b) - 1

    ab = a
    bb = b

    a = min(ab, bb)
    b = max(ab, bb)
    print((a, b))

    friend_list.append((a, b))
    if b in root:
        root[a] = root[b]
    root[b] = a

print(root)

union = []
for i in range(N):
    c_root = i
    while True:
        if c_root in root:
            c_root = root[c_root]
        else:
            union.append(c_root)
            break


for i in range(K):
    s = input()
    a, b = s.split(" ")
    a = int(a) - 1
    b = int(b) - 1
    block_list.append((a, b))


result = []
for i in range(N):
    ret = 0
    if union[i] is None:
        result.append(0)
        continue
    for j in range(N):
        if i == j:
            continue
        if union[i] != union[j]:
            continue
        if (i, j) in block_list:
            continue
        if (j, i) in block_list:
            continue
        if (i, j) in friend_list:
            continue
        if (j, i) in friend_list:
            continue
        ret += 1
    result.append(ret)

print(root)
print(union)
print(" ".join([str(i) for i in result]))

Submission status: Wrong Answer

Solution code:
import numpy as np
N,M,K = list(map(int,input().split()))
R = np.array([[0]*N]*N)

for i in range(M):
  a,b = list(map(int,input().split()))
  R[a-1][b-1] = 2*N
  R[b-1][a-1] = 2*N

for i in range(K):
  c,d = list(map(int,input().split()))
  R[c-1][d-1] = -2*N
  R[d-1][c-1] = -2*N

def rink(i):
  res = [0]*N
  for j in range(N):
    if R[i][j] > 1:
      res[j] = 1
  return res

def rev(ans,res):
  res = ans + res
  for i in range(N):
    if res[i] <= 0:
      res[i] = 0
    elif res[i] < N:
      res[i] = 1
    else:
      res[i] = 0
  return res

ANS = np.array([[0]*N]*N)
for p,r in enumerate(R):
  ans = r
  for i in range(N):
    if ans[i] > 0:
      res = rink(i)
      t = rev(ans,res)
      c = 0
      while sum(ans-t) != 0:
        if c > N:break
        c += 1
        ans = t
        for j in range(N):
          if t[j] > 0:
            res = rink(j)
            t = rev(t,res)
            
  ANS[p] = ans

def trim(x):
  if x == 1:
    return 1
  else:
    return 0


ANS = ANS + R
for i,a in enumerate(ANS):
  ANS[i] = list(map(trim, a))

ans = ''
for a in ANS:
  ans += str(sum(a)-1) + ' '

print(ans[:-1])

Submission status: Wrong Answer

Solution code:

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

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def __str__(self):
        return '\n'.join('{}: {}'.format(root, self.members(root)) for root in self.roots())

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

uf_friend = UnionFind(n+1)
uf_block = UnionFind(n+1)
count = [0]*(n+1)
for i in range(m):
    a,b = map(int, input().split(" "))
    uf_friend.union(a, b)
    count[a] += 1
    count[b] += 1

for i in range(k):
    a,b = map(int, input().split(" "))
    if(uf_friend.issame(a,b)):
        count[a] += 1
        count[b] += 1

result = [0]*n
for i in range(1,n+1):
    result[i-1] = uf_friend.count(i) - count[i] - 1

print(result)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = [0] * m
b = [0] * m
c = [0] * k
d = [0] * k

label = [0] * n
kosu_label = 1

block = [0] * n

ans = [0] * n

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

for i in range(n):
    if label[i] == 0:
        label[i] = kosu_label
    for j in range(len(friend[i])):
        if label[friend[i][j] - 1] == 0:
            label[friend[i][j] - 1] = label[i]
        elif label[friend[i][j] - 1] < label[i]:
            label[i] = label[friend[i][j] - 1]
        elif label[friend[i][j] - 1] > label[i]:
            label[friend[i][j] - 1] = label[i]
            
    kosu_label = kosu_label + 1

for i in range(n):
    for j in range(len(friend[i])):
        if label[friend[i][j] - 1] != label[i]:
            label[friend[i][j] - 1] = min(label[friend[i][j] - 1], label[i])
            label[i] = min(label[friend[i][j] - 1], label[i])

label_s = [0] * kosu_label

for i in range(n):
    label_s[label[i]] = label_s[label[i]] + 1
    
for w in range(k):
    if label[c[w] - 1] == label[d[w] - 1]:
        block[c[w] - 1] = block[c[w] - 1] + 1
        block[d[w] - 1] = block[d[w] - 1] + 1
            
for i in range(n):
    ans[i] = label_s[label[i]] - len(friend[i]) - block[i] - 1

for i in range(n):
    print(ans[i], end = ' ')

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = [0] * m
b = [0] * m
c = [0] * k
d = [0] * k

label = [0] * n
kosu_label = 1

block = [0] * n

ans = [0] * n

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

for i in range(n):
    if label[i] == 0:
        label[i] = kosu_label
    for j in range(len(friend[i])):
        if label[friend[i][j] - 1] == 0:
            label[friend[i][j] - 1] = label[i]
        elif label[friend[i][j] - 1] < label[i]:
            label[i] = label[friend[i][j] - 1]
        elif label[friend[i][j] - 1] > label[i]:
            label[friend[i][j] - 1] = label[i]
            
    kosu_label = kosu_label + 1

for i in range(n):
    for j in range(len(friend[i])):
        if label[friend[i][j] - 1] > label[i]:
            label[friend[i][j] - 1] = label[i]

label_s = [0] * kosu_label

for i in range(n):
    label_s[label[i]] = label_s[label[i]] + 1
    
for w in range(k):
    if label[c[w] - 1] == label[d[w] - 1]:
        block[c[w] - 1] = block[c[w] - 1] + 1
        block[d[w] - 1] = block[d[w] - 1] + 1
            
for i in range(n):
    ans[i] = label_s[label[i]] - len(friend[i]) - block[i] - 1

for i in range(n):
    print(ans[i], end = ' ')

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = [0] * m
b = [0] * m
c = [0] * k
d = [0] * k

label = [0] * n
kosu_label = 1

block = [0] * n

ans = [0] * n

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

for i in range(n):
    if label[i] == 0:
        label[i] = kosu_label
    for j in range(len(friend[i])):
        if label[friend[i][j] - 1] == 0:
            label[friend[i][j] - 1] = label[i]
        elif label[friend[i][j] - 1] < label[i]:
            label[i] = label[friend[i][j] - 1]
        elif label[friend[i][j] - 1] > label[i]:
            label[friend[i][j] - 1] = label[i]
            
    kosu_label = kosu_label + 1

print(friend)
    
for i in range(n):
    for j in range(len(friend[i])):
        if label[friend[i][j] - 1] > label[i]:
            label[friend[i][j] - 1] = label[i]

label_s = [0] * kosu_label

for i in range(n):
    label_s[label[i]] = label_s[label[i]] + 1
    
for w in range(k):
    if label[c[w] - 1] == label[d[w] - 1]:
        block[c[w] - 1] = block[c[w] - 1] + 1
        block[d[w] - 1] = block[d[w] - 1] + 1
            
for i in range(n):
    ans[i] = label_s[label[i]] - len(friend[i]) - block[i] - 1

for i in range(n):
    print(ans[i], end = ' ')

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = [0] * m
b = [0] * m
c = [0] * k
d = [0] * k

label = [0] * n
kosu_label = 1

block = [0] * n

ans = [0] * n

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

for i in range(n):
    if label[i] == 0:
        label[i] = kosu_label
    for j in range(len(friend[i])):
        if label[friend[i][j] - 1] == 0:
            label[friend[i][j] - 1] = label[i]
        elif label[friend[i][j] - 1] < label[i]:
            label[i] = label[friend[i][j] - 1]
        elif label[friend[i][j] - 1] > label[i]:
            label[friend[i][j] - 1] = label[i]
            
    kosu_label = kosu_label + 1  
    
for i in range(n):
    for j in range(len(friend[i])):
        if label[friend[i][j] - 1] < label[i]:
            label[i] = label[friend[i][j] - 1]

label_s = [0] * kosu_label

for i in range(n):
    label_s[label[i]] = label_s[label[i]] + 1
    
for w in range(k):
    if label[c[w] - 1] == label[d[w] - 1]:
        block[c[w] - 1] = block[c[w] - 1] + 1
        block[d[w] - 1] = block[d[w] - 1] + 1
            
for i in range(n):
    ans[i] = label_s[label[i]] - len(friend[i]) - block[i] - 1

for i in range(n):
    print(ans[i], end = ' ')

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = [0] * m
b = [0] * m
c = [0] * k
d = [0] * k

label = [0] * n
kosu_label = 1

block = [0] * n

ans = [0] * n

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

for i in range(n):
    if label[i] == 0:
        label[i] = kosu_label
    for j in range(len(friend[i])):
        if label[friend[i][j] - 1] == 0:
            label[friend[i][j] - 1] = label[i]
        elif label[friend[i][j] - 1] < label[i]:
            label[i] = label[friend[i][j] - 1]
        elif label[friend[i][j] - 1] > label[i]:
            label[friend[i][j] - 1] = label[i]
            
    kosu_label = kosu_label + 1  

label_s = [0] * kosu_label

for i in range(n):
    label_s[label[i]] = label_s[label[i]] + 1
    
for w in range(k):
    if label[c[w] - 1] == label[d[w] - 1]:
        block[c[w] - 1] = block[c[w] - 1] + 1
        block[d[w] - 1] = block[d[w] - 1] + 1
            
for i in range(n):
    ans[i] = label_s[label[i]] - len(friend[i]) - block[i] - 1

for i in range(n):
    print(ans[i], end = ' ')

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = [0] * m
b = [0] * m
c = [0] * k
d = [0] * k

label = [0] * n
kosu_label = 1

block = [0] * n

ans = [0] * n

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

for i in range(n):
    if label[i] == 0:
        label[i] = kosu_label
    for j in range(len(friend[i])):
        if label[friend[i][j] - 1] == 0:
            label[friend[i][j] - 1] = label[i]
        elif label[friend[i][j] - 1] < label[i]:
            label[i] = label[friend[i][j] - 1]
        elif label[friend[i][j] - 1] > label[i]:
            label[friend[i][j] - 1] = label[i]
            
    kosu_label = kosu_label + 1  
    
for i in range(n):
    for j in range(len(friend[i])):
        if label[friend[i][j] - 1] > label[i]:
            label[friend[i][j] - 1] = label[i]

label_s = [0] * kosu_label

for i in range(n):
    label_s[label[i]] = label_s[label[i]] + 1
    
for w in range(k):
    if label[c[w] - 1] == label[d[w] - 1]:
        block[c[w] - 1] = block[c[w] - 1] + 1
        block[d[w] - 1] = block[d[w] - 1] + 1
            
for i in range(n):
    ans[i] = label_s[label[i]] - len(friend[i]) - block[i] - 1

for i in range(n):
    print(ans[i], end = ' ')

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = [0] * m
b = [0] * m
c = [0] * k
d = [0] * k

label = [0] * n
kosu_label = 1

block = [0] * n

ans = [0] * n

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

for i in range(n):
    if label[i] == 0:
        label[i] = kosu_label
    for j in range(len(friend[i])):
        if label[friend[i][j] - 1] == 0:
            label[friend[i][j] - 1] = label[i]
        elif label[friend[i][j] - 1] != label[i]:
            label[i] = min(label[friend[i][j] - 1], label[i])
            label[friend[i][j] - 1] = min(label[friend[i][j] - 1], label[i])
            
    kosu_label = kosu_label + 1  
    
for i in range(n):
    for j in range(len(friend[i])):
        if label[friend[i][j] - 1] > label[i]:
            label[friend[i][j] - 1] = label[i]

label_s = [0] * kosu_label

for i in range(n):
    label_s[label[i]] = label_s[label[i]] + 1
    
for w in range(k):
    if label[c[w] - 1] == label[d[w] - 1]:
        block[c[w] - 1] = block[c[w] - 1] + 1
        block[d[w] - 1] = block[d[w] - 1] + 1
            
for i in range(n):
    ans[i] = label_s[label[i]] - len(friend[i]) - block[i] - 1

for i in range(n):
    print(ans[i], end = ' ')

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = [0] * m
b = [0] * m
c = [0] * k
d = [0] * k

label = [0] * n
kosu_label = 1

block = [0] * n

ans = [0] * n

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

for i in range(n):
    if label[i] == 0:
        label[i] = kosu_label
    for j in range(len(friend[i])):
        if label[friend[i][j] - 1] == 0:
            label[friend[i][j] - 1] = label[i]
        elif label[friend[i][j] - 1] != label[i]:
            label[i] = min(label[friend[i][j] - 1], label[i])
            label[friend[i][j] - 1] = min(label[friend[i][j] - 1], label[i])
            
    kosu_label = kosu_label + 1    

label_s = [0] * kosu_label

for i in range(n):
    label_s[label[i]] = label_s[label[i]] + 1
    


for w in range(k):
    if label[c[w] - 1] == label[d[w] - 1]:
        block[c[w] - 1] = block[c[w] - 1] + 1
        block[d[w] - 1] = block[d[w] - 1] + 1
            
for i in range(n):
    ans[i] = label_s[label[i]] - len(friend[i]) - block[i] - 1

for i in range(n):
    print(ans[i], end = ' ')

Submission status: Wrong Answer

Solution code:
import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce

sys.setrecursionlimit(4100000)
from functools import lru_cache

INF = 1 << 60

#Union Find
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())
direct = [[0 for j in range(n)] for i in range(n)]
# print(direct)
uf = UnionFind(n)
# print(uf)
for i in range(m + k):
    a, b = map(int, input().split())
    direct[a - 1][b - 1] = 1
    direct[b - 1][a - 1] = 1
    if i < m:
        uf.union(a - 1, b - 1)
# print(uf)
# print(direct)
for i in range(n):
    ans = 0
    for j in range(n):
        if i == j:
            continue
        if direct[i][j] == 0 and uf.same(i, direct[i][j]):
            ans += 1
    print("%d " % ans, end="")