Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(100000)
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(M)]
AB.reverse()
par=list(range(1,N+1))
size=[1]*N

ans=[(N-1)*N//2]*M

def spar(n):
  if par[n-1]==n:
    return n
  else:
    return spar(par[n-1])

for i in range(0,M-1):
  A,B=AB[i]
  pa,pb=spar(par[A-1]),spar(par[B-1])
  if pa==pb:
    ans[i+1]=ans[i]
  else:
    ans[i+1]=ans[i]-size[pa-1]*size[pb-1]
    sa,sb=size[pa-1],size[pb-1]
    size[pa-1]+=sb
    size[pb-1]+=sa
  par[pa-1]=pa
  par[pb-1]=pa
  
for i in reversed(ans):
  print(i)

Fixed submission:
import sys
sys.setrecursionlimit(100000)
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(M)]
AB.reverse()
par=list(range(1,N+1))
size=[1]*N

ans=[(N-1)*N//2]*M

def spar(n):
  if par[n-1]==n:
    return n
  else:
    par[n-1]=spar(par[n-1])
    return par[n-1]

for i in range(0,M-1):
  A,B=AB[i]
  pa,pb=spar(par[A-1]),spar(par[B-1])
  if pa==pb:
    ans[i+1]=ans[i]
  else:
    ans[i+1]=ans[i]-size[pa-1]*size[pb-1]
    sa,sb=size[pa-1],size[pb-1]
    size[pa-1]+=sb
    size[pb-1]+=sa
  par[pa-1]=pa
  par[pb-1]=pa
  
for i in reversed(ans):
  print(i)

Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(M)]
AB.reverse()
par=list(range(1,N+1))
size=[1]*N

ans=[(N-1)*N//2]*M

def spar(n):
  if par[n-1]==n:
    return n
  else:
    return spar(par[n-1])

for i in range(0,M-1):
  A,B=AB[i]
  pa,pb=spar(par[A-1]),spar(par[B-1])
  if pa==pb:
    ans[i+1]=ans[i]
  else:
    ans[i+1]=ans[i]-size[pa-1]*size[pb-1]
    sa,sb=size[pa-1],size[pb-1]
    size[pa-1]+=sb
    size[pb-1]+=sa
  par[pa-1]=pa
  par[pb-1]=pa
  
for i in reversed(ans):
  print(i)

Fixed submission:
import sys
sys.setrecursionlimit(100000)
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(M)]
AB.reverse()
par=list(range(1,N+1))
size=[1]*N

ans=[(N-1)*N//2]*M

def spar(n):
  if par[n-1]==n:
    return n
  else:
    par[n-1]=spar(par[n-1])
    return par[n-1]

for i in range(0,M-1):
  A,B=AB[i]
  pa,pb=spar(par[A-1]),spar(par[B-1])
  if pa==pb:
    ans[i+1]=ans[i]
  else:
    ans[i+1]=ans[i]-size[pa-1]*size[pb-1]
    sa,sb=size[pa-1],size[pb-1]
    size[pa-1]+=sb
    size[pb-1]+=sa
  par[pa-1]=pa
  par[pb-1]=pa
  
for i in reversed(ans):
  print(i)

Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(M)]
AB.reverse()
par=list(range(1,N+1))
size=[1]*N

ans=[(N-1)*N//2]*M

def spar(n):
  if par[n-1]==n:
    return n
  else:
    return spar(par[n-1])

for i in range(0,M-1):
  A,B=AB[i]
  pa,pb=spar(par[A-1]),spar(par[B-1])
  if pa==pb:
    ans[i+1]=ans[i]
  else:
    ans[i+1]=ans[i]-size[pa-1]*size[pb-1]
    sa,sb=size[pa-1],size[pb-1]
    size[pa-1]+=sb
    size[pb-1]+=sa
  par[pa-1]=pa
  par[pb-1]=pa
  
for i in reversed(ans):
  print(i)

Fixed submission:
import sys
sys.setrecursionlimit(100000)
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(M)]
AB.reverse()
par=list(range(1,N+1))
size=[1]*N

ans=[(N-1)*N//2]*M

def spar(n):
  if par[n-1]==n:
    return n
  else:
    par[n-1]=spar(par[n-1])
    return par[n-1]

for i in range(0,M-1):
  A,B=AB[i]
  pa,pb=spar(par[A-1]),spar(par[B-1])
  if pa==pb:
    ans[i+1]=ans[i]
  else:
    ans[i+1]=ans[i]-size[pa-1]*size[pb-1]
    sa,sb=size[pa-1],size[pb-1]
    size[pa-1]+=sb
    size[pb-1]+=sa
  par[pa-1]=pa
  par[pb-1]=pa
  
for i in reversed(ans):
  print(i)