Buggy python submission (verdict: Time Limit Exceeded):
sn,bn=map(int,input().split(" "))
fu=[int(sn*(sn-1)/2)]
gr_si=[n for n in range(sn+1)]
siL_gr=[[n] for n in range(sn+1)]
siL_br=[]
for _ in range(bn):
    siL_br.append(list(map(int, input().split(" "))))
siL_br=siL_br[::-1]

for bri in range(bn-1):
    si1,si2=siL_br[bri]
    gr1 = gr_si[si1]
    gr2 = gr_si[si2]
    if gr1==gr2:
        fu.append(fu[bri])
    else:
        lengr1 = len(siL_gr[gr1])
        lengr2 = len(siL_gr[gr2])
#        if lengr1<lengr2:
#            gr1,gr2=gr2,gr1
        fu.append(fu[bri]-lengr1*lengr2)
        for si in siL_gr[gr2]:
            gr_si[si]=gr1
        siL_gr[gr1]+=siL_gr[gr2]
        siL_gr[gr2]=[]

print(*fu[::-1],sep="\n")


Fixed submission:
sn,bn=map(int,input().split(" "))
fu=[int(sn*(sn-1)/2)]
gr_si=[n for n in range(sn+1)]
siL_gr=[[n] for n in range(sn+1)]
siL_br=[]
for _ in range(bn):
    siL_br.append(list(map(int, input().split(" "))))
siL_br=siL_br[::-1]

for bri in range(bn-1):
    si1,si2=siL_br[bri]
    gr1 = gr_si[si1]
    gr2 = gr_si[si2]
    if gr1==gr2:
        fu.append(fu[bri])
    else:
        lengr1 = len(siL_gr[gr1])
        lengr2 = len(siL_gr[gr2])
        if lengr1<lengr2:
            gr1,gr2=gr2,gr1
        fu.append(fu[bri]-lengr1*lengr2)
        for si in siL_gr[gr2]:
            gr_si[si]=gr1
        siL_gr[gr1]+=siL_gr[gr2]
        siL_gr[gr2]=[]

print(*fu[::-1],sep="\n")

Buggy python submission (verdict: Time Limit Exceeded):
sn,bn=map(int,input().split(" "))
fubensa=[int(sn*(sn-1)/2)]
if bn>1:
    br=[]
    for _ in range(bn):
        br.append(list(map(int, input().split(" "))))
    br=br[::-1]
    sg=[0 for n in range(sn+1)]
    sg[br[0][0]]=1
    sg[br[0][1]]=1
    gn=1
    fubensa.append(fubensa[0]-1)
    sgc=[0,2]

    for bri in range(1,bn-1):
        si1=br[bri][0]
        si2=br[bri][1]
        sg1=sg[si1]
        sg2=sg[si2]
        if sg1+sg2==0:
            gn+=1
            sg[si1],sg[si2]=gn,gn
            sgc.append(2)
            fubensa.append(fubensa[bri]-1)
        elif sg1==0:
            fubensa.append(fubensa[bri] - sgc[sg2])
            sg[si1]=sg2
            sgc[sg2]+=1
        elif sg2==0:
            fubensa.append(fubensa[bri] - sgc[sg1])
            sg[si2]=sg1
            sgc[sg1] += 1
        elif sg1!=sg2:
            fubensa.append(fubensa[bri] - sgc[sg1]*sgc[sg2])
            if sgc[sg1]<sgc[sg2]:
                sg1,sg2=sg2,sg1
            sgc[sg1]+=sgc[sg2]
            sg=[sg1 if x==sg2 else x for x in sg]
        else:
            fubensa.append(fubensa[bri])
for x in fubensa[::-1]:
    print(x)

Fixed submission:
sn,bn=map(int,input().split(" "))
fu=[int(sn*(sn-1)/2)]
gr_si=[n for n in range(sn+1)]
siL_gr=[[n] for n in range(sn+1)]
siL_br=[]
for _ in range(bn):
    siL_br.append(list(map(int, input().split(" "))))
siL_br=siL_br[::-1]

for bri in range(bn-1):
    si1,si2=siL_br[bri]
    gr1 = gr_si[si1]
    gr2 = gr_si[si2]
    if gr1==gr2:
        fu.append(fu[bri])
    else:
        lengr1 = len(siL_gr[gr1])
        lengr2 = len(siL_gr[gr2])
        if lengr1<lengr2:
            gr1,gr2=gr2,gr1
        fu.append(fu[bri]-lengr1*lengr2)
        for si in siL_gr[gr2]:
            gr_si[si]=gr1
        siL_gr[gr1]+=siL_gr[gr2]
        siL_gr[gr2]=[]

print(*fu[::-1],sep="\n")

Buggy python submission (verdict: Time Limit Exceeded):
sn,bn=map(int,input().split(" "))
fubensa=[int(sn*(sn-1)/2)]
if bn>1:
    br=[]
    for _ in range(bn):
        br.append(list(map(int, input().split(" "))))
    br=br[::-1]
    sg=[0 for n in range(sn+1)]
    sg[br[0][0]]=1
    sg[br[0][1]]=1
    gn=1
    fubensa.append(fubensa[0]-1)

    for bri in range(1,bn-1):
        si1=br[bri][0]
        si2=br[bri][1]
        sg1=sg[si1]
        sg2=sg[si2]
        if sg1+sg2==0:
            gn+=1
            sg[si1],sg[si2]=gn,gn
            fubensa.append(fubensa[bri]-1)
        elif sg1==0:
            fubensa.append(fubensa[bri] - sg.count(sg2))
            sg[si1]=sg2
        elif sg2==0:
            fubensa.append(fubensa[bri] - sg.count(sg1))
            sg[si2]=sg1
        elif sg1!=sg2:
            sg1c=sg.count(sg1)
            sg2c=sg.count(sg2)
            if sg1c<sg2c:
                sg1,sg2=sg2,sg1
            fubensa.append(fubensa[bri] - sg1c*sg2c)
            sg=[sg1 if x==sg2 else x for x in sg]
        else:
            fubensa.append(fubensa[bri])
for x in fubensa[::-1]:
    print(x)

Fixed submission:
sn,bn=map(int,input().split(" "))
fu=[int(sn*(sn-1)/2)]
gr_si=[n for n in range(sn+1)]
siL_gr=[[n] for n in range(sn+1)]
siL_br=[]
for _ in range(bn):
    siL_br.append(list(map(int, input().split(" "))))
siL_br=siL_br[::-1]

for bri in range(bn-1):
    si1,si2=siL_br[bri]
    gr1 = gr_si[si1]
    gr2 = gr_si[si2]
    if gr1==gr2:
        fu.append(fu[bri])
    else:
        lengr1 = len(siL_gr[gr1])
        lengr2 = len(siL_gr[gr2])
        if lengr1<lengr2:
            gr1,gr2=gr2,gr1
        fu.append(fu[bri]-lengr1*lengr2)
        for si in siL_gr[gr2]:
            gr_si[si]=gr1
        siL_gr[gr1]+=siL_gr[gr2]
        siL_gr[gr2]=[]

print(*fu[::-1],sep="\n")

Buggy python submission (verdict: Time Limit Exceeded):
sn,bn=map(int,input().split(" "))
fubensa=[int(sn*(sn-1)/2)]
if bn>1:
    br=[]
    for _ in range(bn):
        br.append(list(map(int, input().split(" "))))
    br=br[::-1]
    sg=[0 for n in range(sn+1)]
    sg[br[0][0]]=1
    sg[br[0][1]]=1
    gn=1
    fubensa.append(fubensa[0]-1)
    sgc=[0,2]

    for bri in range(1,bn-1):
        si1=br[bri][0]
        si2=br[bri][1]
        sg1=sg[si1]
        sg2=sg[si2]
        if sg1+sg2==0:
            gn+=1
            sg[si1],sg[si2]=gn,gn
            sgc.append(2)
            fubensa.append(fubensa[bri]-1)
        elif sg1==0:
            fubensa.append(fubensa[bri] - sgc[sg2])
            sg[si1]=sg2
            sgc[sg2]+=1
        elif sg2==0:
            fubensa.append(fubensa[bri] - sgc[sg1])
            sg[si2]=sg1
            sgc[sg1] += 1
        elif sg1!=sg2:
            fubensa.append(fubensa[bri] - sgc[sg1]*sgc[sg2])
            sgc[sg1]+=sgc[sg2]
            sg=[sg1 if x==sg2 else x for x in sg]
        else:
            fubensa.append(fubensa[bri])
for x in fubensa[::-1]:
    print(x)

Fixed submission:
sn,bn=map(int,input().split(" "))
fu=[int(sn*(sn-1)/2)]
gr_si=[n for n in range(sn+1)]
siL_gr=[[n] for n in range(sn+1)]
siL_br=[]
for _ in range(bn):
    siL_br.append(list(map(int, input().split(" "))))
siL_br=siL_br[::-1]

for bri in range(bn-1):
    si1,si2=siL_br[bri]
    gr1 = gr_si[si1]
    gr2 = gr_si[si2]
    if gr1==gr2:
        fu.append(fu[bri])
    else:
        lengr1 = len(siL_gr[gr1])
        lengr2 = len(siL_gr[gr2])
        if lengr1<lengr2:
            gr1,gr2=gr2,gr1
        fu.append(fu[bri]-lengr1*lengr2)
        for si in siL_gr[gr2]:
            gr_si[si]=gr1
        siL_gr[gr1]+=siL_gr[gr2]
        siL_gr[gr2]=[]

print(*fu[::-1],sep="\n")

Buggy python submission (verdict: Time Limit Exceeded):
sn,bn=map(int,input().split(" "))
fubensa=[int(sn*(sn-1)/2)]
if bn>1:
    br=[]
    for _ in range(bn):
        br.append(list(map(int, input().split(" "))))
    br=br[::-1]
    sg=[0 for n in range(sn+1)]
    sg[br[0][0]]=1
    sg[br[0][1]]=1
    gn=1
    fubensa.append(fubensa[0]-1)
    for bri in range(1,bn-1):
        si1=br[bri][0]
        si2=br[bri][1]
        sg1=sg[si1]
        sg2=sg[si2]
        if sg1+sg2==0:
            gn+=1
            sg[si1],sg[si2]=gn,gn
            fubensa.append(fubensa[bri]-1)
        elif sg1==0:
            fubensa.append(fubensa[bri] - sg.count(sg2))
            sg[si1]=sg2
        elif sg2==0:
            fubensa.append(fubensa[bri] - sg.count(sg1))
            sg[si2]=sg1
        elif sg1!=sg2:
            fubensa.append(fubensa[bri] - sg.count(sg1)*sg.count(sg2))
            sg=[sg1 if x==sg2 else x for x in sg]
        else:
            fubensa.append(fubensa[bri])
for x in fubensa[::-1]:
    print(x)

Fixed submission:
sn,bn=map(int,input().split(" "))
fu=[int(sn*(sn-1)/2)]
gr_si=[n for n in range(sn+1)]
siL_gr=[[n] for n in range(sn+1)]
siL_br=[]
for _ in range(bn):
    siL_br.append(list(map(int, input().split(" "))))
siL_br=siL_br[::-1]

for bri in range(bn-1):
    si1,si2=siL_br[bri]
    gr1 = gr_si[si1]
    gr2 = gr_si[si2]
    if gr1==gr2:
        fu.append(fu[bri])
    else:
        lengr1 = len(siL_gr[gr1])
        lengr2 = len(siL_gr[gr2])
        if lengr1<lengr2:
            gr1,gr2=gr2,gr1
        fu.append(fu[bri]-lengr1*lengr2)
        for si in siL_gr[gr2]:
            gr_si[si]=gr1
        siL_gr[gr1]+=siL_gr[gr2]
        siL_gr[gr2]=[]

print(*fu[::-1],sep="\n")