Problem p02762 (python)

Fixed submission:
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan,sqrt
import cmath as cma
import copy as cp
import sys
import re
sys.setrecursionlimit(10**7)
EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf
MOD = 10**9 + 7

def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def adj(n): return [[] for _ in range(n)]

class unionfind():
    def __init__(self, n):
        self.n = n
        # 中身が負の数なら根であり、数字の絶対値はグループ数
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0: return x
        self.parents[x] = self.find(self.parents[x])
        return self.parents[x]
    def union(self, x, y):
        x,y = self.find(x), 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())

n,m,k = imap()
uf = unionfind(n)
f,ng,anss = iarr(n),iarr(n),iarr(n)

for i in range(m):
    a,b = imap()
    a,b = a-1,b-1
    f[a] += 1
    f[b] += 1
    uf.union(a,b)

for i in range(n):
    anss[i] = uf.size(i) - f[i] - 1

for i in range(k):
    c,d = imap()
    c,d = c-1,d-1
    if uf.same(c,d):
        anss[c] -= 1
        anss[d] -= 1

print(*anss)

Buggy submission (verdict: Runtime Error):
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan,sqrt
import cmath as cma
import copy as cp
import sys
import re
import bisect as bs
sys.setrecursionlimit(10**7)
EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf
MOD = 10**9 + 7

def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def adj(n): return [[] for _ in range(n)]

class unionfind:
    def __init__(self, n):
        self.parent = [i for i in range(n)]
        self.size = [1 for i in range(n)]
    def find(self,a):
        if a == self.parent[a]: return a
        else: self.parent[a] = find(self,self.parent[a]); return self.parent[a]
    def unite(self,a,b):
        pa,pb = self.find(self,a), self.find(self,b)
        if pa == pb: return
        else: self.parent[pb] = pa; self.size[pa] += self.size[pb]
    def same(self,a,b): return find(self,a) == find(self,b)


n,m,k = imap()
ab = np.array([iarr() for i in range(n)]) -1
#a,b = ab.T[0], ab.T[1]
uf = unionfind(n)

f = iarr(n)
for a,b in ab:
    uf.unite(a,b)
    f[a] += 1; f[b] += 1

ng = iarr(n)
for i in range(k):
    c,d = imap()
    if uf.same(c,d): ng[c] += 1; ng[d] += 1

anss = []
for i in range(n):
    ans = uf.size(i) - f[i] - ng[i] - 1
    anss.append(ans)
print(*anss)