Problem p02762 (python)

Fixed submission:
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
class UnionFind():
    def __init__(self, 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 resolve():
    N, M, K = lr()
    uf = UnionFind(N)
    fr = [0]*N
    for i in range(M):
        a, b = lr()
        uf.union(a-1, b-1)
        fr[a-1] += 1
        fr[b-1] += 1
    ans = [uf.size(x) - fr[x] - 1 for x in range(N)]
    for i in range(K):
        c, d = lr()
        if uf.same(c-1, d-1):
            ans[c-1] -= 1
            ans[d-1] -= 1
    print(*ans, sep=' ')
resolve()

Buggy submission (verdict: Runtime Error):
import numpy as np
def resolve():
    N, M, K = map(int, input().split())
    fri = np.zeros((N, N), np.int64)
    for i in range(M):
        a, b = map(int, input().split())
        fri[a-1][b-1] = 1
        fri[b-1][a-1] = 1
    blo = np.zeros((N, N), np.int64)
    for i in range(K):
        c, d = map(int, input().split())
        blo[c-1][d-1] = 1
        blo[d-1][c-1] = 1

    can = np.zeros((N, N), np.int64)
    for i in range(N):
        vis = [False for _ in range(N)]
        s = [i]
        while len(s) > 0:
            v = s.pop()
            vis[v] = True
            for j, k in enumerate(fri[v]):
                if vis[j] or k == 0:
                    continue
                s.append(j)
                if fri[i][j] != 1 and blo[i][j] != 1 and can[i][j] == 0:
                    can[i][j] = 1
    ans = []
    for i in range(N):
        ans.append(can[i].sum())
    print(*ans, sep=' ')
resolve()

Buggy submission (verdict: Runtime Error):
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
import numpy as np
def resolve():
    N, M, K = map(int, input().split())
    fri = np.zeros((N, N), np.int64)
    for i in range(M):
        a, b = map(int, input().split())
        fri[a-1][b-1] = 1
        fri[b-1][a-1] = 1
    blo = np.zeros((N, N), np.int64)
    for i in range(K):
        c, d = map(int, input().split())
        blo[c-1][d-1] = 1
        blo[d-1][c-1] = 1

    can = np.zeros((N, N), np.int64)
    for i in range(N):
        vis = [False for _ in range(N)]
        s = [i]
        while len(s) > 0:
            v = s.pop()
            vis[v] = True
            for j, k in enumerate(fri[v]):
                if vis[j] or k == 0:
                    continue
                s.append(j)
                if fri[i][j] != 1 and blo[i][j] != 1 and can[i][j] == 0:
                    can[i][j] = 1
    ans = []
    for i in range(N):
        ans.append(can[i].sum())
    print(*ans, sep=' ')
resolve()