Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(20000)
N, M = [int(i) for i in input().split()]
parent = [i for i in range(N+1)]
node_num = [1 for i in range(N+1)]
def find(x):
    if parent[x] == x:
        return x
    else:
        parent[x] = find(parent[x])
        return parent[x]

bridge = []
for i in range(M):
    A, B = [int(i) for i in input().split()]
    bridge.append([A, B])

bridge = bridge[::-1]
ans_rev = [N*(N-1)//2]
combi = 0
for i in range(M-1):
    A, B = bridge[i]
    r_A = find(A)
    r_B = find(B)
    if r_A != r_B:
        parent[r_B] = r_A
        combi += node_num[r_B] * node_num[r_A]
        node_num[r_A] += node_num[r_B]
    ans_rev.append(N*(N-1)//2-combi)

ans = ans_rev[::-1]
print(*ans, sep="\n"

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

N, M = [int(i) for i in input().split()]
parent = [i for i in range(N+1)]
node_num = [1 for i in range(N+1)]
def find(x):
    if parent[x] == x:
        return x
    else:
        parent[x] = find(parent[x])
        return parent[x]

bridge = []
for i in range(M):
    A, B = [int(i) for i in input().split()]
    bridge.append([A, B])

bridge = bridge[::-1]
ans_rev = [N*(N-1)//2]
combi = 0
for i in range(M-1):
    A, B = bridge[i]
    r_A = find(A)
    r_B = find(B)
    if r_A != r_B:
        parent[r_B] = r_A
        combi += node_num[r_B] * node_num[r_A]
        node_num[r_A] += node_num[r_B]
    ans_rev.append(N*(N-1)//2-combi)

ans = ans_rev[::-1]
print(*ans, sep="\n")

Buggy python submission (verdict: Time Limit Exceeded):
N, M = [int(i) for i in input().split()]
parent = [i for i in range(N+1)]
node_num = [1 for i in range(N+1)]
def find(x):
    if parent[x] == x:
        return x
    else:
        parent[x] = find(parent[x])
        return parent[x]

def find_for(x):
    while parent[x] != x:
        x = parent[x]
    return x

bridge = []
for i in range(M):
    A, B = [int(i) for i in input().split()]
    bridge.append([A, B])

bridge = bridge[::-1]
ans_rev = [N*(N-1)//2]
combi = 0
for i in range(M-1):
    A, B = bridge[i]
    r_A = find_for(A)
    r_B = find_for(B)
    if r_A != r_B:
        parent[r_B] = r_A
        combi += node_num[r_B] * node_num[r_A]
        node_num[r_A] += node_num[r_B]
    ans_rev.append(N*(N-1)//2-combi)

ans = ans_rev[::-1]
print(*ans, sep="\n")


Fixed submission:
import sys
sys.setrecursionlimit(10**6)

N, M = [int(i) for i in input().split()]
parent = [i for i in range(N+1)]
node_num = [1 for i in range(N+1)]
def find(x):
    if parent[x] == x:
        return x
    else:
        parent[x] = find(parent[x])
        return parent[x]

bridge = []
for i in range(M):
    A, B = [int(i) for i in input().split()]
    bridge.append([A, B])

bridge = bridge[::-1]
ans_rev = [N*(N-1)//2]
combi = 0
for i in range(M-1):
    A, B = bridge[i]
    r_A = find(A)
    r_B = find(B)
    if r_A != r_B:
        parent[r_B] = r_A
        combi += node_num[r_B] * node_num[r_A]
        node_num[r_A] += node_num[r_B]
    ans_rev.append(N*(N-1)//2-combi)

ans = ans_rev[::-1]
print(*ans, sep="\n")

Buggy python submission (verdict: Runtime Error):
N, M = [int(i) for i in input().split()]
parent = [i for i in range(N+1)]
node_num = [1 for i in range(N+1)]
def find(x):
    if parent[x] == x:
        return x
    else:
        parent[x] = find(parent[x])
        return parent[x]

bridge = []
for i in range(M):
    A, B = [int(i) for i in input().split()]
    bridge.append([A, B])

bridge = bridge[::-1]
ans_rev = [N*(N-1)//2]
combi = 0
for i in range(M-1):
    A, B = bridge[i]
    r_A = find(A)
    r_B = find(B)
    if r_A != r_B:
        parent[r_B] = r_A
        combi += node_num[r_B] * node_num[r_A]
        node_num[r_A] += node_num[r_B]
    ans_rev.append(N*(N-1)//2-combi)

ans = ans_rev[::-1]
print(*ans, sep="\n")


Fixed submission:
import sys
sys.setrecursionlimit(10**6)

N, M = [int(i) for i in input().split()]
parent = [i for i in range(N+1)]
node_num = [1 for i in range(N+1)]
def find(x):
    if parent[x] == x:
        return x
    else:
        parent[x] = find(parent[x])
        return parent[x]

bridge = []
for i in range(M):
    A, B = [int(i) for i in input().split()]
    bridge.append([A, B])

bridge = bridge[::-1]
ans_rev = [N*(N-1)//2]
combi = 0
for i in range(M-1):
    A, B = bridge[i]
    r_A = find(A)
    r_B = find(B)
    if r_A != r_B:
        parent[r_B] = r_A
        combi += node_num[r_B] * node_num[r_A]
        node_num[r_A] += node_num[r_B]
    ans_rev.append(N*(N-1)//2-combi)

ans = ans_rev[::-1]
print(*ans, sep="\n")

Buggy python submission (verdict: Time Limit Exceeded):
N, M = [int(i) for i in input().split()]
bridge = []
for i in range(M):
    A, B = [int(i) for i in input().split()]
    bridge.append([A, B])

bridge = bridge[::-1]
ans_rev = [N*(N-1)//2]
G = []
combi = 0
for i in range(M-1):
    A, B = bridge[i]
    g_A = -1
    g_B = -1
    for j, g in enumerate(G):
        if A in g:
            g_A = j
        if B in g:
            g_B = j
    if g_A == -1 and g_B == -1:
        G.append([A, B])
        combi += 1
    elif g_A == -1:
        combi += len(G[g_B])
        G[g_B].append(A)
    elif g_B == -1:
        combi += len(G[g_A])
        G[g_A].append(B)
    elif g_A != g_B:
        combi += len(G[g_A]) * len(G[g_B])
        G[g_A].extend(G[g_B])
        del G[g_B]
    ans_rev.append(N*(N-1)//2-combi)

ans = ans_rev[::-1]
print(*ans, sep="\n")


Fixed submission:
import sys
sys.setrecursionlimit(10**6)

N, M = [int(i) for i in input().split()]
parent = [i for i in range(N+1)]
node_num = [1 for i in range(N+1)]
def find(x):
    if parent[x] == x:
        return x
    else:
        parent[x] = find(parent[x])
        return parent[x]

bridge = []
for i in range(M):
    A, B = [int(i) for i in input().split()]
    bridge.append([A, B])

bridge = bridge[::-1]
ans_rev = [N*(N-1)//2]
combi = 0
for i in range(M-1):
    A, B = bridge[i]
    r_A = find(A)
    r_B = find(B)
    if r_A != r_B:
        parent[r_B] = r_A
        combi += node_num[r_B] * node_num[r_A]
        node_num[r_A] += node_num[r_B]
    ans_rev.append(N*(N-1)//2-combi)

ans = ans_rev[::-1]
print(*ans, sep="\n")