Buggy python submission (verdict: Runtime Error):
import sys
n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(m)]
sys.setrecursionlimit(m)
ans = n * (n - 1) // 2
result = [ans]
leader = [-1] * n
size = [1] * n


def leader_check(i):
    if leader[i] == -1:
        return i
    ln = leader_check(leader[i])
    leader[i] = ln
    return ln

for a, b in ab[:0:-1]:
    a, b = a - 1, b - 1
    la = leader_check(a)
    lb = leader_check(b)
    if la != lb:
        leader[la] = lb
        ans -= size[la] * size[lb]
        size[lb] += size[la]
    result.append(ans)

for i in result[::-1]:
    print(i)


Fixed submission:
import sys
sys.setrecursionlimit(10**5)
n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(m)]

ans = n * (n - 1) // 2
result = [ans]
leader = [-1] * n
size = [1] * n


def leader_check(i):
    if leader[i] == -1:
        return i
    ln = leader_check(leader[i])
    leader[i] = ln
    return ln

for a, b in ab[:0:-1]:
    a, b = a - 1, b - 1
    la = leader_check(a)
    lb = leader_check(b)
    if la != lb:
        leader[la] = lb
        ans -= size[la] * size[lb]
        size[lb] += size[la]
    result.append(ans)

for i in result[::-1]:
    print(i)

Buggy python submission (verdict: Runtime Error):
n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(m)]
ans = n * (n - 1) // 2
result = [ans]
leader = [-1] * n
size = [1] * n
def leader_check(i):
    if leader[i]==-1:
        return i
    ln=leader_check(leader[i])
    leader[i]=ln
    return ln

for a, b in ab[:0:-1]:
    a, b = a - 1, b - 1
    la=leader_check(a)
    lb=leader_check(b)
    if la!=lb:
        leader[la]=lb
        ans-=size[la]*size[lb]
        size[lb]+=size[la]
    result.append(ans)

for i in result[::-1]:
    print(i)

Fixed submission:
import sys
sys.setrecursionlimit(10**5)
n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(m)]

ans = n * (n - 1) // 2
result = [ans]
leader = [-1] * n
size = [1] * n


def leader_check(i):
    if leader[i] == -1:
        return i
    ln = leader_check(leader[i])
    leader[i] = ln
    return ln

for a, b in ab[:0:-1]:
    a, b = a - 1, b - 1
    la = leader_check(a)
    lb = leader_check(b)
    if la != lb:
        leader[la] = lb
        ans -= size[la] * size[lb]
        size[lb] += size[la]
    result.append(ans)

for i in result[::-1]:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(m)]
hb = n * (n - 1) // 2
result = [hb]
leder = [i for i in range(1, n + 1)]
size = [1 for i in range(n)]
for brk in ab[:0:-1]:
    if size[leder[brk[0] - 1] - 1] < size[leder[brk[1] - 1] - 1]:
        brk = brk[::-1]
    if leder[brk[0] - 1] != leder[brk[1] - 1]:
        hb -= size[leder[brk[0] - 1] - 1] * size[leder[brk[1] - 1] - 1]
        size[leder[brk[0] - 1] - 1] += size[leder[brk[1] - 1] - 1]
        size[leder[brk[1] - 1] - 1] = 0
    result.append(hb)
    leder = [i if i != leder[brk[1] - 1] else leder[brk[0] - 1] for i in leder]
for i in result[::-1]:
    print(i)


Fixed submission:
import sys
sys.setrecursionlimit(10**5)
n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(m)]

ans = n * (n - 1) // 2
result = [ans]
leader = [-1] * n
size = [1] * n


def leader_check(i):
    if leader[i] == -1:
        return i
    ln = leader_check(leader[i])
    leader[i] = ln
    return ln

for a, b in ab[:0:-1]:
    a, b = a - 1, b - 1
    la = leader_check(a)
    lb = leader_check(b)
    if la != lb:
        leader[la] = lb
        ans -= size[la] * size[lb]
        size[lb] += size[la]
    result.append(ans)

for i in result[::-1]:
    print(i)

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

n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(m)]
hb = n * (n - 1) // 2
result = [hb]
leder = [i for i in range(1, n + 1)]
size = [1 for i in range(n)]
for brk in ab[:0:-1]:
    if size[leder[brk[0] - 1] - 1] < size[leder[brk[1] - 1] - 1]:
        brk = brk[::-1]
    if leder[brk[0] - 1] != leder[brk[1] - 1]:
        hb -= size[leder[brk[0] - 1] - 1] * size[leder[brk[1] - 1] - 1]
        size[leder[brk[0] - 1] - 1] += size[leder[brk[1] - 1] - 1]
        size[leder[brk[1] - 1] - 1] = 0
    result.append(hb)
    # leder[leder[brk[1]-1]-1]=leder[brk[0]-1]
    leder = [i if i != leder[brk[1] - 1] else leder[brk[0] - 1] for i in leder]
for i in result[::-1]:
    print(i)


Fixed submission:
import sys
sys.setrecursionlimit(10**5)
n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(m)]

ans = n * (n - 1) // 2
result = [ans]
leader = [-1] * n
size = [1] * n


def leader_check(i):
    if leader[i] == -1:
        return i
    ln = leader_check(leader[i])
    leader[i] = ln
    return ln

for a, b in ab[:0:-1]:
    a, b = a - 1, b - 1
    la = leader_check(a)
    lb = leader_check(b)
    if la != lb:
        leader[la] = lb
        ans -= size[la] * size[lb]
        size[lb] += size[la]
    result.append(ans)

for i in result[::-1]:
    print(i)