Buggy python submission (verdict: Time Limit Exceeded):
n,m = list(map(int, input().split()))
isla=[0 for i in range(n+1)]
bri=[]
crus=[[] for i in range(n)]
num=[0 for i in range(n)]
score=[]
crusmax=0
for i in range(m):
    a,b = list(map(int, input().split()))
    bri.append([a,b])

bri.reverse()
#print(bri)

for i in range(m):
    a=bri[i][0]
    b=bri[i][1]
    if(isla[a]==0 and isla[b]==0):
        crusmax+=1
        crus[crusmax].append(a)
        crus[crusmax].append(b)
        isla[a]=crusmax
        isla[b]=crusmax
        num[crusmax]=2
    elif(isla[a]==0):
        isla[a]=isla[b]
        crus[isla[b]].append(a)
        num[isla[b]]+=1
    elif(isla[b]==0):
        isla[b]=isla[a]
        crus[isla[a]].append(b)
        num[isla[a]]+=1
    elif(isla[a]<isla[b]):
        color=isla[b]
        for j in range(len(crus[isla[b]])):
            isla[crus[color][j]]=isla[a]
            crus[isla[a]].append(crus[color][j])
        crus[color]=[]
        num[isla[a]]+=num[color]
        num[color]=0
    elif(isla[a]>isla[b]):
        color=isla[a]
        for j in range(len(crus[isla[a]])):
            isla[crus[color][j]]=isla[b]
            crus[isla[b]].append(crus[color][j])
        crus[color]=[]
        num[isla[b]]+=num[color]
        num[color]=0
    #print("bri[i]",bri[i])
    #print("isla",isla)
    #print("crus",crus)
    #print("num",num)
    
    total=0
    for j in range(crusmax+1):
        total+=(num[j]*(num[j]-1))//2
    score.append(total)
    #print("total",total)
    #print()
            

score.reverse()
for i in range(len(score)):
    score[i]=(n*(n-1))//2 - score[i]
score.append((n*(n-1))//2)
score=score[1:]
for i in range(len(score)):
    print(score[i])

Fixed submission:
n,m = list(map(int, input().split()))
isla=[0 for i in range(n+1)]
bri=[]
crus=[[] for i in range(n)]
num=[0 for i in range(n)]
score=[]
crusmax=0

plusnum=-1
minusnum=-1
newnum=-1
plusval=[0,0]
minusval=[0,0]


for i in range(m):
    a,b = list(map(int, input().split()))
    bri.append([a,b])

bri.reverse()
#print(bri)

for i in range(m):
    a=bri[i][0]
    b=bri[i][1]
    if(isla[a]==0 and isla[b]==0):
        crusmax+=1
        crus[crusmax].append(a)
        crus[crusmax].append(b)
        isla[a]=crusmax
        isla[b]=crusmax
        num[crusmax]=2
        [plusnum,minusnum,newnum]=[0,0,crusmax]
    elif(isla[a]==0):
        isla[a]=isla[b]
        crus[isla[b]].append(a)
        num[isla[b]]+=1
        [plusnum,minusnum,newnum]=[isla[b],0,0]
        plusval=[num[isla[b]]-1,num[isla[b]]]
    elif(isla[b]==0):
        isla[b]=isla[a]
        crus[isla[a]].append(b)
        num[isla[a]]+=1
        [plusnum,minusnum,newnum]=[isla[a],0,0]
        plusval=[num[isla[a]]-1,num[isla[a]]]
    elif(isla[a]<isla[b]):
        color=isla[b]
        dif=len(crus[isla[b]])
        for j in range(len(crus[isla[b]])):
            isla[crus[color][j]]=isla[a]
            crus[isla[a]].append(crus[color][j])
        crus[color]=[]
        num[isla[a]]+=num[color]
        num[color]=0
        [plusnum,minusnum,newnum]=[isla[a],color,0]
        plusval=[num[isla[a]]-dif,num[isla[a]]]
        minusval=[dif,0]
    elif(isla[a]>isla[b]):
        color=isla[a]
        dif=len(crus[isla[a]])
        for j in range(len(crus[isla[a]])):
            isla[crus[color][j]]=isla[b]
            crus[isla[b]].append(crus[color][j])
        crus[color]=[]
        num[isla[b]]+=num[color]
        num[color]=0
        [plusnum,minusnum,newnum]=[isla[b],color,0]
        plusval=[num[isla[b]]-dif,num[isla[b]]]
        minusval=[dif,0]
    else:
        [plusnum,minusnum,newnum]=[0,0,0]
    #print("bri[i]",bri[i])
    #print("isla",isla)
    #print("crus",crus)
    #print("num",num)
    
    if(i==0):
        total=0
    else:
        total=score[-1]
    if(newnum!=0):
        total+=1
    if(plusnum!=0):
        total+=(plusval[1]*(plusval[1]-1))//2
        total-=(plusval[0]*(plusval[0]-1))//2
    if(minusnum!=0):
        total+=(minusval[1]*(minusval[1]-1))//2
        total-=(minusval[0]*(minusval[0]-1))//2
    score.append(total)
    #print("total",total)
    #print()
            

score.reverse()
for i in range(len(score)):
    score[i]=(n*(n-1))//2 - score[i]
score.append((n*(n-1))//2)
score=score[1:]
for i in range(len(score)):
    print(score[i])