Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(100000)

data = input().split()
n = int(data[0])
m = int(data[1])
edge=[]
for i in range(m):
    tmp = []
    data = input().split()
    tmp.append(int(data[0])-1)
    tmp.append(int(data[1])-1)
    edge.append(tmp)

grp=list(range(0, n))
def group(num):
    if grp[num] == num:
        return num
    return group(grp[num])

def merge(num1, num2):
    grp[num2]=grp[num1]

res=[]
ans = [1]*n
ben = int(n*(n-1)/2)
edge.reverse()
for e in edge:
    #print(e, ans, ben, grp)
    res.append(ben)
    g0 = group(e[0])
    g1 = group(e[1])
    if g0 != g1:
        ben -= ans[g0]*ans[g1]
        sum = ans[g0]+ans[g1]
        merge(g0, g1)
        ans[g0]=sum
        ans[g1]=sum

res.reverse()
for r in res:
    print(r)

#print(int(n*(n-1)/2))

Fixed submission:
import sys
sys.setrecursionlimit(100000)

data = input().split()
n = int(data[0])
m = int(data[1])
edge=[]
for i in range(m):
    tmp = []
    data = input().split()
    tmp.append(int(data[0])-1)
    tmp.append(int(data[1])-1)
    edge.append(tmp)

grp=list(range(0, n))
def group(num):
    if grp[num] == num:
        return num
    return group(grp[num])

def merge(p_num, c_num):
    grp[c_num]=grp[p_num]

res=[]
ans = [1]*n
ben = int(n*(n-1)/2)
edge.reverse()
for e in edge:
    #print(e, ans, ben, grp)
    res.append(ben)
    g0 = group(e[0])
    g1 = group(e[1])
    if g0 != g1:
        ben -= ans[g0]*ans[g1]
        sum = ans[g0]+ans[g1]
        if ans[g0] > ans[g1]:
            merge(g0, g1)
        else:
            merge(g1, g0)
        ans[g0]=sum
        ans[g1]=sum

res.reverse()
for r in res:
    print(r)

#print(int(n*(n-1)/2))

Buggy python submission (verdict: Runtime Error):
data = input().split()
n = int(data[0])
m = int(data[1])
edge=[]
for i in range(m):
    tmp = []
    data = input().split()
    tmp.append(int(data[0])-1)
    tmp.append(int(data[1])-1)
    edge.append(tmp)

grp=list(range(0, n))
def group(num):
    if grp[num] != num:
        return group(grp[num])
    return num

def merge(num1, num2):
    grp[num2]=grp[num1]

res=[]
ans = [1]*n
ben = int(n*(n-1)/2)
edge.reverse()
for e in edge:
    #print(e, ans, ben, grp)
    res.append(ben)
    g0 = group(e[0])
    g1 = group(e[1])
    if g0 != g1:
        ben -= ans[g0]*ans[g1]
        sum = ans[g0]+ans[g1]
        merge(g0, g1)
        ans[g0]=sum

res.reverse()
for r in res:
    print(r)

#print(int(n*(n-1)/2))

Fixed submission:
import sys
sys.setrecursionlimit(100000)

data = input().split()
n = int(data[0])
m = int(data[1])
edge=[]
for i in range(m):
    tmp = []
    data = input().split()
    tmp.append(int(data[0])-1)
    tmp.append(int(data[1])-1)
    edge.append(tmp)

grp=list(range(0, n))
def group(num):
    if grp[num] == num:
        return num
    return group(grp[num])

def merge(p_num, c_num):
    grp[c_num]=grp[p_num]

res=[]
ans = [1]*n
ben = int(n*(n-1)/2)
edge.reverse()
for e in edge:
    #print(e, ans, ben, grp)
    res.append(ben)
    g0 = group(e[0])
    g1 = group(e[1])
    if g0 != g1:
        ben -= ans[g0]*ans[g1]
        sum = ans[g0]+ans[g1]
        if ans[g0] > ans[g1]:
            merge(g0, g1)
        else:
            merge(g1, g0)
        ans[g0]=sum
        ans[g1]=sum

res.reverse()
for r in res:
    print(r)

#print(int(n*(n-1)/2))

Buggy python submission (verdict: Runtime Error):
data = input().split()
n = int(data[0])
m = int(data[1])
edge=[]
for i in range(m):
    tmp = []
    data = input().split()
    tmp.append(int(data[0])-1)
    tmp.append(int(data[1])-1)
    edge.append(tmp)

grp=list(range(0, n))
def group(num):
    if grp[num] != num:
        return group(grp[num])
    return num

def merge(num1, num2):
    grp[num2]=grp[num1]

res=[]
ans = [1]*n
ben = int(n*(n-1)/2)
edge.reverse()
for e in edge:
    #print(e, ans, ben, grp)
    res.append(ben)
    if group(e[0]) != group(e[1]):
        ben -= ans[group(e[0])]*ans[group(e[1])]
        sum = ans[group(e[0])]+ans[group(e[1])]
        merge(group(e[0]), group(e[1]))
        ans[group(e[0])]=sum

res.reverse()
for r in res:
    print(r)

#print(int(n*(n-1)/2))

Fixed submission:
import sys
sys.setrecursionlimit(100000)

data = input().split()
n = int(data[0])
m = int(data[1])
edge=[]
for i in range(m):
    tmp = []
    data = input().split()
    tmp.append(int(data[0])-1)
    tmp.append(int(data[1])-1)
    edge.append(tmp)

grp=list(range(0, n))
def group(num):
    if grp[num] == num:
        return num
    return group(grp[num])

def merge(p_num, c_num):
    grp[c_num]=grp[p_num]

res=[]
ans = [1]*n
ben = int(n*(n-1)/2)
edge.reverse()
for e in edge:
    #print(e, ans, ben, grp)
    res.append(ben)
    g0 = group(e[0])
    g1 = group(e[1])
    if g0 != g1:
        ben -= ans[g0]*ans[g1]
        sum = ans[g0]+ans[g1]
        if ans[g0] > ans[g1]:
            merge(g0, g1)
        else:
            merge(g1, g0)
        ans[g0]=sum
        ans[g1]=sum

res.reverse()
for r in res:
    print(r)

#print(int(n*(n-1)/2))

Buggy python submission (verdict: Time Limit Exceeded):
data = input().split()
n = int(data[0])
m = int(data[1])
edge=[]
for i in range(m):
    tmp = []
    data = input().split()
    tmp.append(int(data[0]))
    tmp.append(int(data[1]))
    edge.append(tmp)

res=[]
ans = list(range(1, n+1))
edge.reverse()
for e in edge:
    tmp=int(n*(n-1)/2)
    for j in range(1, n+1):
        c = ans.count(j)
        tmp -= int(c*(c-1)/2)
    res.append(tmp)
    ans = [ans[e[0]-1] if s == ans[e[1]-1] else s for s in ans]

res.reverse()
for r in res:
    print(r)

#print(int(n*(n-1)/2))

Fixed submission:
import sys
sys.setrecursionlimit(100000)

data = input().split()
n = int(data[0])
m = int(data[1])
edge=[]
for i in range(m):
    tmp = []
    data = input().split()
    tmp.append(int(data[0])-1)
    tmp.append(int(data[1])-1)
    edge.append(tmp)

grp=list(range(0, n))
def group(num):
    if grp[num] == num:
        return num
    return group(grp[num])

def merge(p_num, c_num):
    grp[c_num]=grp[p_num]

res=[]
ans = [1]*n
ben = int(n*(n-1)/2)
edge.reverse()
for e in edge:
    #print(e, ans, ben, grp)
    res.append(ben)
    g0 = group(e[0])
    g1 = group(e[1])
    if g0 != g1:
        ben -= ans[g0]*ans[g1]
        sum = ans[g0]+ans[g1]
        if ans[g0] > ans[g1]:
            merge(g0, g1)
        else:
            merge(g1, g0)
        ans[g0]=sum
        ans[g1]=sum

res.reverse()
for r in res:
    print(r)

#print(int(n*(n-1)/2))

Buggy python submission (verdict: Time Limit Exceeded):
data = input().split()
n = int(data[0])
m = int(data[1])
edge=[]
for i in range(m):
    tmp = []
    data = input().split()
    tmp.append(int(data[0]))
    tmp.append(int(data[1]))
    edge.append(tmp)

for i in range(m):
    ans = list(range(1, n+1))
    edge.pop(0)
    for j in edge:
        ans = [ans[j[0]-1] if s == ans[j[1]-1] else s for s in ans]

    res=int(n*(n-1)/2)
    for j in range(1, n+1):
        c = ans.count(j)
        res -= int(c*(c-1)/2)
    print(res)

Fixed submission:
import sys
sys.setrecursionlimit(100000)

data = input().split()
n = int(data[0])
m = int(data[1])
edge=[]
for i in range(m):
    tmp = []
    data = input().split()
    tmp.append(int(data[0])-1)
    tmp.append(int(data[1])-1)
    edge.append(tmp)

grp=list(range(0, n))
def group(num):
    if grp[num] == num:
        return num
    return group(grp[num])

def merge(p_num, c_num):
    grp[c_num]=grp[p_num]

res=[]
ans = [1]*n
ben = int(n*(n-1)/2)
edge.reverse()
for e in edge:
    #print(e, ans, ben, grp)
    res.append(ben)
    g0 = group(e[0])
    g1 = group(e[1])
    if g0 != g1:
        ben -= ans[g0]*ans[g1]
        sum = ans[g0]+ans[g1]
        if ans[g0] > ans[g1]:
            merge(g0, g1)
        else:
            merge(g1, g0)
        ans[g0]=sum
        ans[g1]=sum

res.reverse()
for r in res:
    print(r)

#print(int(n*(n-1)/2))