Buggy python submission (verdict: Time Limit Exceeded):
def search_root(l, n):
    i = n
    while l[i] != i:
        i = l[i]
    return i


def set_root(l, root_index, start_index):
    i = start_index
    while l[i] != root_index:
        tmp = i
        i = l[i]
        l[tmp] = root_index


def func(n):
    return (n * (n - 1)) // 2


node_size, input_size = [int(i) for i in input().split()]

br = []
for _ in range(input_size):
    br.append([int(i) for i in input().split()])

cnt_list = [func(node_size)]
size_list = [1 for _ in range(node_size + 1)]
node_list = [i for i in range(node_size + 1)]

for i in range(1, input_size + 1):
    node1, node2 = br[-i]

    root1, root2 = search_root(node_list, node1), search_root(node_list, node2)

    if root1 == root2:
        tmp = cnt_list[0]
    else:
        tmp = cnt_list[0] - (size_list[root1] * size_list[root2])
        if size_list[root1] < size_list[root2]:
            node_list[root1] = root2
            size_list[root2] += size_list[root1]
        else:
            node_list[root2] = root1
            size_list[root1] += size_list[root2]

    if tmp is 0:
        for _ in range(input_size - i):
            print(0)
        break
    cnt_list.insert(0, tmp)

for i in cnt_list:
    print(i)

Fixed submission:
def search_root(l, n):
    i = n
    while l[i] != i:
        i = l[i]
    return i


def set_root(l, root_index, start_index):
    i = start_index
    while l[i] != root_index:
        tmp = i
        i = l[i]
        l[tmp] = root_index


def func(n):
    return (n * (n - 1)) // 2


node_size, input_size = [int(i) for i in input().split()]

br = []
for _ in range(input_size):
    br.append([int(i) for i in input().split()])

cnt_list = [0]
size_list = [1 for _ in range(node_size + 1)]
node_list = [i for i in range(node_size + 1)]

for i in range(1, input_size + 1):
    node1, node2 = br[-i]

    root1, root2 = search_root(node_list, node1), search_root(node_list, node2)

    if root1 == root2:
        cnt_list.append(cnt_list[-1])
    else:
        cnt_list.append(cnt_list[-1] + (size_list[root1] * size_list[root2]))
        if size_list[root1] < size_list[root2]:
            node_list[root1] = root2
            size_list[root2] += size_list[root1]
        else:
            node_list[root2] = root1
            size_list[root1] += size_list[root2]

val = func(node_size)
for i in cnt_list[::-1][1:]:
    print(val - i)

Buggy python submission (verdict: Time Limit Exceeded):
def search_root(l, n):
    i = n
    while l[i] != 0:
        i = l[i]
    return i

def func(n):
    return (n * (n - 1)) // 2


node_size, input_size = [int(i) for i in input().split()]

br = []
for _ in range(input_size):
    br.append([int(i) for i in input().split()])

cnt_list = [func(node_size)]
size_list = [0 for _ in range(node_size + 1)]
node_list = [i for i in range(node_size + 1)]

for i in range(1, input_size + 1):
    node1, node2 = br[-i]

    if node_list[node1] == node1 and node_list[node2] == node2:
        node_list[node1] = 0
        node_list[node2] = node1
        new_size = cnt_list[0] - 1
        size_list[node1] = 2
    elif node_list[node1] == node1:
        tmp_root = search_root(node_list, node2)
        if node_list[node2]:
            node_list[node2] = tmp_root
        node_list[node1] = tmp_root
        new_size = cnt_list[0] - size_list[tmp_root]
        size_list[tmp_root] += 1
    elif node_list[node2] == node2:
        tmp_root = search_root(node_list, node1)
        if node_list[node1]:
            node_list[node1] = tmp_root
        node_list[node2] = tmp_root
        new_size = cnt_list[0] - size_list[tmp_root]
        size_list[tmp_root] += 1
    else:
        tmp_root1 = search_root(node_list, node1)
        tmp_root2 = search_root(node_list, node2)
        if tmp_root1 == tmp_root2:
            tmp = cnt_list[0]
        else:
            if node_list[node1]:
                node_list[node1] = tmp_root1
            node_list[node2] = tmp_root1
            node_list[tmp_root2] = tmp_root1
            new_size = cnt_list[0] - (size_list[tmp_root1] * size_list[tmp_root2])
            size_list[tmp_root1] += size_list[tmp_root2]

    if new_size is 0:
        for _ in range(input_size - i):
            print(0)
        break
    cnt_list.insert(0, new_size)

for i in cnt_list:
    print(i)

Fixed submission:
def search_root(l, n):
    i = n
    while l[i] != i:
        i = l[i]
    return i


def set_root(l, root_index, start_index):
    i = start_index
    while l[i] != root_index:
        tmp = i
        i = l[i]
        l[tmp] = root_index


def func(n):
    return (n * (n - 1)) // 2


node_size, input_size = [int(i) for i in input().split()]

br = []
for _ in range(input_size):
    br.append([int(i) for i in input().split()])

cnt_list = [0]
size_list = [1 for _ in range(node_size + 1)]
node_list = [i for i in range(node_size + 1)]

for i in range(1, input_size + 1):
    node1, node2 = br[-i]

    root1, root2 = search_root(node_list, node1), search_root(node_list, node2)

    if root1 == root2:
        cnt_list.append(cnt_list[-1])
    else:
        cnt_list.append(cnt_list[-1] + (size_list[root1] * size_list[root2]))
        if size_list[root1] < size_list[root2]:
            node_list[root1] = root2
            size_list[root2] += size_list[root1]
        else:
            node_list[root2] = root1
            size_list[root1] += size_list[root2]

val = func(node_size)
for i in cnt_list[::-1][1:]:
    print(val - i)

Buggy python submission (verdict: Runtime Error):
def func(n):
    return (n * (n - 1)) // 2


node_size, input_size = [int(i) for i in input().split()]

br = [func(node_size)]
for _ in range(input_size):
    br.append([int(i) for i in input().split()])

cnt_list = [func(node_size)]

index = 0
node_to_group = {}
group_to_index = {}
index_size = {}

for j in range(1, input_size + 1):
    flag1, flag2 = br[-j][0] in node_to_group, br[-j][1] in node_to_group

    if flag1 and flag2:
        if group_to_index[node_to_group[br[-j][0]]] == group_to_index[node_to_group[br[-j][1]]]:
            tmp = cnt_list[0]
        else:
            tmp = cnt_list[0] + func(index_size[group_to_index[node_to_group[br[-j][0]]]]) + \
                  func(index_size[group_to_index[node_to_group[br[-j][1]]]]) - \
                  func(index_size[group_to_index[node_to_group[br[-j][0]]]] +
                       index_size[group_to_index[node_to_group[br[-j][1]]]])
            index_size[group_to_index[node_to_group[br[-j][0]]]] += index_size[group_to_index[node_to_group[br[-j][1]]]]
            del index_size[group_to_index[node_to_group[br[-j][1]]]]
            group_to_index[node_to_group[br[-j][1]]] = group_to_index[node_to_group[br[-j][0]]]

    elif flag1:
        tmp = cnt_list[0] - index_size[group_to_index[node_to_group[br[-j][0]]]]
        node_to_group[br[-j][1]] = node_to_group[br[-j][0]]
        index_size[group_to_index[node_to_group[br[-j][0]]]] += 1
    elif flag2:
        tmp = cnt_list[0] - index_size[group_to_index[node_to_group[br[-j][1]]]]
        node_to_group[br[-j][0]] = node_to_group[br[-j][1]]
        index_size[group_to_index[node_to_group[br[-j][1]]]] += 1
    else:
        tmp = cnt_list[0] - 1
        node_to_group[br[-j][0]] = br[-j][0]
        node_to_group[br[-j][1]] = br[-j][0]
        group_to_index[br[-j][0]] = index
        index_size[index] = 2
        index += 1
    
    if tmp == 0:
        for _ in range(input_size - j):
            print(0)
        break
    cnt_list.insert(0, tmp)

for i in cnt_list:
    print(i)

Fixed submission:
def search_root(l, n):
    i = n
    while l[i] != i:
        i = l[i]
    return i


def set_root(l, root_index, start_index):
    i = start_index
    while l[i] != root_index:
        tmp = i
        i = l[i]
        l[tmp] = root_index


def func(n):
    return (n * (n - 1)) // 2


node_size, input_size = [int(i) for i in input().split()]

br = []
for _ in range(input_size):
    br.append([int(i) for i in input().split()])

cnt_list = [0]
size_list = [1 for _ in range(node_size + 1)]
node_list = [i for i in range(node_size + 1)]

for i in range(1, input_size + 1):
    node1, node2 = br[-i]

    root1, root2 = search_root(node_list, node1), search_root(node_list, node2)

    if root1 == root2:
        cnt_list.append(cnt_list[-1])
    else:
        cnt_list.append(cnt_list[-1] + (size_list[root1] * size_list[root2]))
        if size_list[root1] < size_list[root2]:
            node_list[root1] = root2
            size_list[root2] += size_list[root1]
        else:
            node_list[root2] = root1
            size_list[root1] += size_list[root2]

val = func(node_size)
for i in cnt_list[::-1][1:]:
    print(val - i)

Buggy python submission (verdict: Runtime Error):
def func(n):
    return (n * (n - 1)) // 2


node_size, input_size = [int(i) for i in input().split()]

br = [func(node_size)]
for _ in range(input_size):
    br.append([int(i) for i in input().split()])

cnt_list = [func(node_size)]

index = 0
node_to_group = {}
group_to_index = {}
index_size = {}

for j in range(1, input_size + 1):
    flag1, flag2 = br[-j][0] in node_to_group, br[-j][1] in node_to_group

    if flag1 and flag2:
        if group_to_index[node_to_group[br[-j][0]]] == group_to_index[node_to_group[br[-j][1]]]:
            tmp = cnt_list[0]
        else:
            tmp = cnt_list[0] + func(index_size[group_to_index[node_to_group[br[-j][0]]]]) + \
                  func(index_size[group_to_index[node_to_group[br[-j][1]]]]) - \
                  func(index_size[group_to_index[node_to_group[br[-j][0]]]] +
                       index_size[group_to_index[node_to_group[br[-j][1]]]])
            index_size[group_to_index[node_to_group[br[-j][0]]]] += index_size[group_to_index[node_to_group[br[-j][1]]]]
            del index_size[group_to_index[node_to_group[br[-j][1]]]]
            group_to_index[node_to_group[br[-j][1]]] = group_to_index[node_to_group[br[-j][0]]]

    elif flag1:
        tmp = cnt_list[0] - index_size[group_to_index[node_to_group[br[-j][0]]]]
        node_to_group[br[-j][1]] = node_to_group[br[-j][0]]
        index_size[group_to_index[node_to_group[br[-j][0]]]] += 1
    elif flag2:
        tmp = cnt_list[0] - index_size[group_to_index[node_to_group[br[-j][1]]]]
        node_to_group[br[-j][0]] = node_to_group[br[-j][1]]
        index_size[group_to_index[node_to_group[br[-j][1]]]] += 1
    else:
        tmp = cnt_list[0] - 1
        node_to_group[br[-j][0]] = br[-j][0]
        node_to_group[br[-j][1]] = br[-j][0]
        group_to_index[br[-j][0]] = index
        index_size[index] = 2
        index += 1
    print(index_size)
    if tmp == 0:
        for _ in range(input_size - j):
            print(0)
        break
    cnt_list.insert(0, tmp)

for i in cnt_list:
    print(i)

Fixed submission:
def search_root(l, n):
    i = n
    while l[i] != i:
        i = l[i]
    return i


def set_root(l, root_index, start_index):
    i = start_index
    while l[i] != root_index:
        tmp = i
        i = l[i]
        l[tmp] = root_index


def func(n):
    return (n * (n - 1)) // 2


node_size, input_size = [int(i) for i in input().split()]

br = []
for _ in range(input_size):
    br.append([int(i) for i in input().split()])

cnt_list = [0]
size_list = [1 for _ in range(node_size + 1)]
node_list = [i for i in range(node_size + 1)]

for i in range(1, input_size + 1):
    node1, node2 = br[-i]

    root1, root2 = search_root(node_list, node1), search_root(node_list, node2)

    if root1 == root2:
        cnt_list.append(cnt_list[-1])
    else:
        cnt_list.append(cnt_list[-1] + (size_list[root1] * size_list[root2]))
        if size_list[root1] < size_list[root2]:
            node_list[root1] = root2
            size_list[root2] += size_list[root1]
        else:
            node_list[root2] = root1
            size_list[root1] += size_list[root2]

val = func(node_size)
for i in cnt_list[::-1][1:]:
    print(val - i)