Buggy python submission (verdict: Runtime Error):
import math


def find_root(ele):
    root = node_list[ele]['root']
    if root is not None:
        return find_root(root)
    return ele


N, M = list(map(int, input().split()))
bridge_list = list()
for _ in range(M):
    bridge_list.append(list(map(int, input().split())))

answer_list = [math.factorial(N) // math.factorial(2) // math.factorial(N - 2)]
node_list = [{'root': None, 'child_count': 0} for i in range(N)]

for bridge_list in bridge_list[:0:-1]:
    a = bridge_list[0] - 1
    b = bridge_list[1] - 1
    a_root = find_root(a)
    b_root = find_root(b)
    if a_root == a and b_root == b:
        answer_list.append(answer_list[-1] - (node_list[a]['child_count'] + 1) * (node_list[b]['child_count'] + 1))
        next_root = min(a, b)
        old_root = max(a, b)
        node_list[next_root]['child_count'] += node_list[old_root]['child_count'] + 1
        node_list[old_root]['root'] = next_root
    elif a_root == a and b_root != b:
        answer_list.append(answer_list[-1] - (node_list[a]['child_count'] + 1) * (node_list[b_root]['child_count'] + 1))
        node_list[a]['child_count'] += node_list[b_root]['child_count'] + 1
        node_list[b_root]['root'] = a
    elif a_root != a and b_root == b:
        answer_list.append(answer_list[-1] - (node_list[a_root]['child_count'] + 1) * (node_list[b]['child_count'] + 1))
        node_list[b]['child_count'] += node_list[a_root]['child_count'] + 1
        node_list[a_root]['root'] = b
    else:
        answer_list.append(answer_list[-1])

for answer in answer_list[::-1]:
    print(answer)


Fixed submission:
import math


def find_root(ele):
    root = node_list[ele]['root']
    if root is not None:
        return find_root(root)
    return ele


N, M = list(map(int, input().split()))
bridge_list = list()
for _ in range(M):
    bridge_list.append(list(map(int, input().split())))

answer_list = [math.factorial(N) // math.factorial(2) // math.factorial(N - 2)]
node_list = [{'root': None, 'child_count': 0} for i in range(N)]

for bridge_list in bridge_list[:0:-1]:
    a = bridge_list[0] - 1
    b = bridge_list[1] - 1
    a_root = find_root(a)
    b_root = find_root(b)
    if a_root != b_root:
        answer_list.append(answer_list[-1] - (node_list[a_root]['child_count'] + 1) * (node_list[b_root]['child_count'] + 1))
        next_root = min(a_root, b_root)
        old_root = max(a_root, b_root)
        node_list[next_root]['child_count'] += node_list[old_root]['child_count'] + 1
        node_list[old_root]['root'] = next_root
    else:
        answer_list.append(answer_list[-1])

for answer in answer_list[::-1]:
    print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
import math


def get_group_num(ele):
    for i in range(len(group_list)):
        if ele in group_list[i]:
            return i
    raise Exception('could not find ele in any groups')


N, M = list(map(int, input().split()))
bridge_list = list()
for _ in range(M):
    bridge_list.append(list(map(int, input().split())))

answer_list = [math.factorial(N) // math.factorial(2) // math.factorial(N - 2)]
group_list = [[i] for i in range(1, N + 1)]

for bridge_list in bridge_list[:0:-1]:
    a = bridge_list[0]
    b = bridge_list[1]
    a_gid = get_group_num(a)
    b_gid = get_group_num(b)
    if a_gid != b_gid:
        answer_list.append(answer_list[-1] - len(group_list[a_gid]) * len(group_list[b_gid]))
        next_gid = min(a_gid, b_gid)
        old_gid = max(a_gid, b_gid)
        group_list[next_gid] += group_list[old_gid]
        group_list[old_gid] = []
    else:
        answer_list.append(answer_list[-1])

for answer in answer_list[::-1]:
    print(answer)


Fixed submission:
import math


def find_root(ele):
    root = node_list[ele]['root']
    if root is not None:
        return find_root(root)
    return ele


N, M = list(map(int, input().split()))
bridge_list = list()
for _ in range(M):
    bridge_list.append(list(map(int, input().split())))

answer_list = [math.factorial(N) // math.factorial(2) // math.factorial(N - 2)]
node_list = [{'root': None, 'child_count': 0} for i in range(N)]

for bridge_list in bridge_list[:0:-1]:
    a = bridge_list[0] - 1
    b = bridge_list[1] - 1
    a_root = find_root(a)
    b_root = find_root(b)
    if a_root != b_root:
        answer_list.append(answer_list[-1] - (node_list[a_root]['child_count'] + 1) * (node_list[b_root]['child_count'] + 1))
        next_root = min(a_root, b_root)
        old_root = max(a_root, b_root)
        node_list[next_root]['child_count'] += node_list[old_root]['child_count'] + 1
        node_list[old_root]['root'] = next_root
    else:
        answer_list.append(answer_list[-1])

for answer in answer_list[::-1]:
    print(answer)