Buggy python submission (verdict: Runtime Error):

N, M = [int(n) for n in input().split()]
AB = []

P = list(range(N))
P_num = [1] * N

def root(x):
    if P[x] == x:
        return x
    else:
        P[x] = root(P[x])
        return P[x]
        
def unite(x, y):
    P[root(y)] = root(x)
    

for m in range(M):
    A, B = [int(n) - 1 for n in input().split()]
    AB.append((A, B))

convenience = [0]
for i in range(M):
    A, B = AB[M - 1 - i]
    convenience.append(convenience[-1])
    if root(A) != root(B):
        convenience[-1] += P_num[root(A)] * P_num[root(B)]
        next_num = P_num[root(A)] + P_num[root(B)]
        unite(A, B)
        P_num[root(A)] = next_num

for m in range(M):
    print(N * (N - 1) // 2 - convenience[M - 1 - m])

    

Fixed submission:
import sys
sys.setrecursionlimit(1000000)
N, M = [int(n) for n in input().split()]
AB = []

P = list(range(N))
P_num = [1] * N

def root(x):
    if P[x] == x:
        return x
    else:
        P[x] = root(P[x])
        return P[x]
        
def unite(x, y):
    P[root(y)] = root(x)
    

for m in range(M):
    A, B = [int(n) - 1 for n in input().split()]
    AB.append((A, B))

convenience = [0]
for i in range(M):
    A, B = AB[M - 1 - i]
    convenience.append(convenience[-1])
    if root(A) != root(B):
        convenience[-1] += P_num[root(A)] * P_num[root(B)]
        next_num = P_num[root(A)] + P_num[root(B)]
        unite(A, B)
        P_num[root(A)] = next_num

for m in range(M):
    print(N * (N - 1) // 2 - convenience[M - 1 - m])

Buggy python submission (verdict: Runtime Error):

N, M = [int(n) for n in input().split()]
AB = []

P = list(range(N))
P_num = [1] * N

def root(x):
    if P[x] == x:
        return x
    else:
        P[x] = root(P[x])
        return P[x]
        
def unite(x, y):
    P[root(y)] = root(x)
    

for m in range(M):
    A, B = [int(n) - 1 for n in input().split()]
    AB.append((A, B))

convenience = [0]
for i in range(M):
    A, B = AB[M - 1 - i]
    convenience.append(convenience[-1])
    if root(A) != root(B):
        convenience[-1] += P_num[root(A)] * P_num[root(B)]
        next_num = P_num[root(A)] + P_num[root(B)]
        unite(A, B)
        P_num[root(A)] = next_num

for m in range(M):
    print(N * (N - 1) // 2 - convenience[M - 1 - m])

    

Fixed submission:
import sys
sys.setrecursionlimit(1000000)
N, M = [int(n) for n in input().split()]
AB = []

P = list(range(N))
P_num = [1] * N

def root(x):
    if P[x] == x:
        return x
    else:
        P[x] = root(P[x])
        return P[x]
        
def unite(x, y):
    P[root(y)] = root(x)
    

for m in range(M):
    A, B = [int(n) - 1 for n in input().split()]
    AB.append((A, B))

convenience = [0]
for i in range(M):
    A, B = AB[M - 1 - i]
    convenience.append(convenience[-1])
    if root(A) != root(B):
        convenience[-1] += P_num[root(A)] * P_num[root(B)]
        next_num = P_num[root(A)] + P_num[root(B)]
        unite(A, B)
        P_num[root(A)] = next_num

for m in range(M):
    print(N * (N - 1) // 2 - convenience[M - 1 - m])

Buggy python submission (verdict: Runtime Error):

N, M = [int(n) for n in input().split()]
AB = []

P = list(range(N))
P_num = [1] * N

def root(x):
    if P[x] == x:
        return x
    else:
        P[x] = root(P[x])
        return P[x]
        
def unite(x, y):
    P[root(y)] = root(x)
    

for m in range(M):
    A, B = [int(n) - 1 for n in input().split()]
    AB.append((A, B))

# comp_ans[i] = i番目の橋ができたときに減る不便度
comp_ans = [0] * (M + 1)
for m in range(M - 1, 0 - 1, -1):
    A, B = AB[m]
    comp_ans[m] = comp_ans[m + 1]
    if root(A) != root(B):
        comp_ans[m] += P_num[root(A)] * P_num[root(B)]
    buf = P_num[root(A)] + P_num[root(B)]
    unite(A, B)
    P_num[root(A)] = buf



for m in range(1, M + 1):
    print(N * (N - 1) // 2 - comp_ans[m])
    
    

Fixed submission:
import sys
sys.setrecursionlimit(1000000)
N, M = [int(n) for n in input().split()]
AB = []

P = list(range(N))
P_num = [1] * N

def root(x):
    if P[x] == x:
        return x
    else:
        P[x] = root(P[x])
        return P[x]
        
def unite(x, y):
    P[root(y)] = root(x)
    

for m in range(M):
    A, B = [int(n) - 1 for n in input().split()]
    AB.append((A, B))

convenience = [0]
for i in range(M):
    A, B = AB[M - 1 - i]
    convenience.append(convenience[-1])
    if root(A) != root(B):
        convenience[-1] += P_num[root(A)] * P_num[root(B)]
        next_num = P_num[root(A)] + P_num[root(B)]
        unite(A, B)
        P_num[root(A)] = next_num

for m in range(M):
    print(N * (N - 1) // 2 - convenience[M - 1 - m])