Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n,m = [int(i) for i in input().split()]
a = np.array([0]*m)
b = np.array([0]*m)
ans = np.array([0]*m)
ans[m - 1] = n * (n - 1) / 2

for i in range(m):
	a[i],b[i] = [int(i) for i in input().split()]

class UnionFind:
    def __init__(self, n):
        #親の番号を格納する。親だった場合は-(その集合のサイズ)
        #作るときはself.parの値をすべて-1にする
        self.par = [-1 for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
        
    def size(self, x):
        return -self.par[self.find(x)]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return 
        if self.size(x) < self.size(y):
            x , y = y , x
        self.par[x] += self.par[y]
        self.par[y] = x

uni = UnionFind(n)

for i in range(m-1,0,-1):
    ans[i-1] = ans[i]
    if uni.find(a[i]-1) != uni.find(b[i]-1):
        ans[i-1] -= uni.size(a[i]-1)*uni.size(b[i]-1)
    
        uni.union(a[i]-1,b[i]-1)

for i in ans:
    print(i)
    



Fixed submission:
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.size = [1 for _ in range(n+1)]

    # 検索
    def find(self, x):
        if self.par[x] == x:
            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 self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)
    
    
def main():
    N, M = [int(_) for _ in input().split()]
    bridge = [tuple(map(int, input().split())) for _ in range(M)]

    last = []
    last.append(int(N * (N-1) * 0.5))

    ins = UnionFind(N)
    last_temp = 0

    for i in range(M-1):
        #print(ins.par)
        if ins.same_check(bridge[M-1-i][0],bridge[M-1-i][1]):
            last.append(last[-1])
            #ins.union(bridge[M-1-i][0],bridge[M-1-i][1])
        else:
            last_temp = last[-1] - (ins.size[ins.find(bridge[M-1-i][0])]) * (ins.size[ins.find(bridge[M-1-i][1])])
            #print(ins.size,i)
            last.append(last_temp)
            ins.union(bridge[M-1-i][0],bridge[M-1-i][1])
    
    [print(last[M-i-1]) for i in range(M)]
    exit()
    
main()

Buggy python submission (verdict: Runtime Error):
import numpy as np

n,m = [int(i) for i in input().split()]
a = np.array([0]*m)
b = np.array([0]*m)
ans = np.array([0]*m)
ans[m - 1] = n * (n - 1) / 2

for i in range(m):
	a[i],b[i] = [int(i) for i in input().split()]

class UnionFind:
    def __init__(self, n):
        #親の番号を格納する。親だった場合は-(その集合のサイズ)
        #作るときはself.parの値をすべて-1にする
        self.par = [-1 for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
        
    def size(self, x):
        return -self.par[self.find(x)]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return 
        if self.size(x) < self.size(y):
            x , y = y , x
        self.par[x] += self.par[y]
        self.par[y] = x

uni = UnionFind(n)

for i in range(m-1,0,-1):
    ans[i-1] = ans[i]
    if uni.find(a[i]-1) != uni.find(b[i]-1):
        ans[i-1] -= uni.size(a[i]-1)*uni.size(b[i]-1)
    
        uni.union(a[i]-1,b[i]-1)

for i in ans:
    print(i)
    



Fixed submission:
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.size = [1 for _ in range(n+1)]

    # 検索
    def find(self, x):
        if self.par[x] == x:
            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 self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)
    
    
def main():
    N, M = [int(_) for _ in input().split()]
    bridge = [tuple(map(int, input().split())) for _ in range(M)]

    last = []
    last.append(int(N * (N-1) * 0.5))

    ins = UnionFind(N)
    last_temp = 0

    for i in range(M-1):
        #print(ins.par)
        if ins.same_check(bridge[M-1-i][0],bridge[M-1-i][1]):
            last.append(last[-1])
            #ins.union(bridge[M-1-i][0],bridge[M-1-i][1])
        else:
            last_temp = last[-1] - (ins.size[ins.find(bridge[M-1-i][0])]) * (ins.size[ins.find(bridge[M-1-i][1])])
            #print(ins.size,i)
            last.append(last_temp)
            ins.union(bridge[M-1-i][0],bridge[M-1-i][1])
    
    [print(last[M-i-1]) for i in range(M)]
    exit()
    
main()

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n,m = [int(i) for i in input().split()]
a = np.array([0]*m)
b = np.array([0]*m)
ans = np.array([0]*m)
ans[m - 1] = n * (n - 1) / 2

for i in range(m):
	a[i],b[i] = [int(i) for i in input().split()]

class UnionFind:
    def __init__(self, n):
        #親の番号を格納する。親だった場合は-(その集合のサイズ)
        #作るときはself.parの値をすべて-1にする
        self.par = [-1 for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
        
    def size(self, x):
        return -self.par[self.find(x)]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return 
        if self.size(x) < self.size(y):
            x , y = y , x
        self.par[x] += self.par[y]
        self.par[y] = x

uni = UnionFind(n)

for i in range(m-1,0,-1):
    ans[i-1] = ans[i]
    if uni.find(a[i]-1) != uni.find(b[i]-1):
        ans[i-1] -= uni.size(a[i]-1)*uni.size(b[i]-1)
    
        uni.union(a[i]-1,b[i]-1)

for i in ans:
    print(i)

Fixed submission:
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.size = [1 for _ in range(n+1)]

    # 検索
    def find(self, x):
        if self.par[x] == x:
            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 self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)
    
    
def main():
    N, M = [int(_) for _ in input().split()]
    bridge = [tuple(map(int, input().split())) for _ in range(M)]

    last = []
    last.append(int(N * (N-1) * 0.5))

    ins = UnionFind(N)
    last_temp = 0

    for i in range(M-1):
        #print(ins.par)
        if ins.same_check(bridge[M-1-i][0],bridge[M-1-i][1]):
            last.append(last[-1])
            #ins.union(bridge[M-1-i][0],bridge[M-1-i][1])
        else:
            last_temp = last[-1] - (ins.size[ins.find(bridge[M-1-i][0])]) * (ins.size[ins.find(bridge[M-1-i][1])])
            #print(ins.size,i)
            last.append(last_temp)
            ins.union(bridge[M-1-i][0],bridge[M-1-i][1])
    
    [print(last[M-i-1]) for i in range(M)]
    exit()
    
main()

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n,m = [int(i) for i in input().split()]

pair=np.array([list(map(lambda x:int(x)-1,input().split())) for _ in range(m)])
graph=np.array([[0]*n for i in range(n)])

def dfs(v):
    if visited[v]:
        return
    visited[v]=True
    for j in [k for k,v2 in enumerate(graph[v]) if v2 == 1]:
        dfs(j)


for p in pair:
    graph[p[0]][p[1]] = graph[p[1]][p[0]] = 1
#print(graph)  
for i in range(m):
    ans=0
    x,y = pair[i]
    graph[x][y] = graph[y][x] = 0

    for i in range(n):
        visited=[False]*n
        dfs(i)
        #print(visited)
        ans += sum([1 for j in visited[i:] if not j]) 
        
    print(ans)

Fixed submission:
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.size = [1 for _ in range(n+1)]

    # 検索
    def find(self, x):
        if self.par[x] == x:
            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 self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)
    
    
def main():
    N, M = [int(_) for _ in input().split()]
    bridge = [tuple(map(int, input().split())) for _ in range(M)]

    last = []
    last.append(int(N * (N-1) * 0.5))

    ins = UnionFind(N)
    last_temp = 0

    for i in range(M-1):
        #print(ins.par)
        if ins.same_check(bridge[M-1-i][0],bridge[M-1-i][1]):
            last.append(last[-1])
            #ins.union(bridge[M-1-i][0],bridge[M-1-i][1])
        else:
            last_temp = last[-1] - (ins.size[ins.find(bridge[M-1-i][0])]) * (ins.size[ins.find(bridge[M-1-i][1])])
            #print(ins.size,i)
            last.append(last_temp)
            ins.union(bridge[M-1-i][0],bridge[M-1-i][1])
    
    [print(last[M-i-1]) for i in range(M)]
    exit()
    
main()