Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n,m = map(int,input().split())
ab = [[int(i) for i in input().split()]for j in range(m)][1:]
 
ans = [0]*(m-1)+[int(n*(n-1)/2)]
l = np.array([i for i in range(1,n+1)])
s = {i:1 for i in range(1,n+1)}
def serch_l(num):
  if l[num]==num+1:
    return l[num]
  else:
    leader = serch_l(l[num]-1)
    l[num]=leader
    return leader
for k,i in enumerate(ab[::-1]):
  
  if l[i[0]-1] == l[i[1]-1]:
    ans[m-2-k]=ans[m-1-k]
  else:
    l_a,l_b = serch_l(i[0]-1),serch_l(i[1]-1)
    s_a,s_b = s[l_a],s[l_b]
    
    if s_a <= s_b:
      c = s_a*s_b
      s[l_b]+=s_a
      s[l_a]=0
      l[l==l_a]=l_b
      ans[m-2-k]=ans[m-1-k]-c
    else:
      c = s_a*s_b
      s[l_a]+=s_b
      s[l_b]=0
      l[l==l_b]=l_a
      ans[m-2-k]=ans[m-1-k]-c
  if ans[m-2-k]==0:
    break
for i in ans:
  print(i)

Fixed submission:
n,m = map(int,input().split())
ab = [[int(i) for i in input().split()]for j in range(m)][1:]
ans = [0]*(m-1)+[int(n*(n-1)/2)]
l = [i for i in range(1,n+1)]
s = {i:1 for i in range(1,n+1)}
 
def serch_l(num):
  if l[num]==num+1:
    return l[num]
  else:
    leader = serch_l(l[num]-1)
    l[num]=leader
    return leader
    
for k,i in enumerate(ab[::-1]):
  k = m-1-k
  l_a,l_b = serch_l(i[0]-1),serch_l(i[1]-1)
  if l_a==l_b:
    ans[k-1]=ans[k]
  else:
    
    s_a,s_b = s[l_a],s[l_b]
    
    if s_a > s_b:
      (s_a,s_b) = (s_b,s_a)
      (l_a,l_b) = (l_b,l_a)
    c = s_a*s_b
    s[l_b]+=s_a
    s[l_a]=0
    l[l_a-1]=l_b
    ans[k-1]=ans[k]-c
for i in ans:
  print(i)

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
ab = [[int(i) for i in input().split()]for j in range(m)][1:]
ans = [0]*(m-1)+[int(n*(n-1)/2)]
l = [i for i in range(1,n+1)]
s = {i:1 for i in range(1,n+1)}

def serch_l(num):
  if l[num]==num+1:
    return l[num]
  else:
    leader = serch_l(l[num]-1)
    l[num]=leader
    return leader
    

for k,i in enumerate(ab[::-1]):
  k = m-1-k
  
  if l[i[0]-1] == l[i[1]-1]:
    ans[k-1]=ans[k]
  else:
    l_a,l_b = serch_l(i[0]-1),serch_l(i[1]-1)
    s_a,s_b = s[l_a],s[l_b]
    
    if s_a > s_b:
      (s_a,s_b) = (s_b,s_a)
    c = s_a*s_b
    s[l_b]+=s_a
    s[l_a]=0
    l[l_a-1]=l_b
    ans[k-1]=ans[k]-c
for i in ans:
  print(i)


Fixed submission:
n,m = map(int,input().split())
ab = [[int(i) for i in input().split()]for j in range(m)][1:]
ans = [0]*(m-1)+[int(n*(n-1)/2)]
l = [i for i in range(1,n+1)]
s = {i:1 for i in range(1,n+1)}
 
def serch_l(num):
  if l[num]==num+1:
    return l[num]
  else:
    leader = serch_l(l[num]-1)
    l[num]=leader
    return leader
    
for k,i in enumerate(ab[::-1]):
  k = m-1-k
  l_a,l_b = serch_l(i[0]-1),serch_l(i[1]-1)
  if l_a==l_b:
    ans[k-1]=ans[k]
  else:
    
    s_a,s_b = s[l_a],s[l_b]
    
    if s_a > s_b:
      (s_a,s_b) = (s_b,s_a)
      (l_a,l_b) = (l_b,l_a)
    c = s_a*s_b
    s[l_b]+=s_a
    s[l_a]=0
    l[l_a-1]=l_b
    ans[k-1]=ans[k]-c
for i in ans:
  print(i)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n,m = map(int,input().split())
ab = [[int(i) for i in input().split()]for j in range(m)][1:]

ans = [0]*(m-1)+[int(n*(n-1)/2)]
l = np.array([i for i in range(1,n+1)])
s = {i:1 for i in range(1,n+1)}
for k,i in enumerate(ab[::-1]):
  
  if l[i[0]-1] == l[i[1]-1]:
    ans[m-2-k]=ans[m-1-k]
  else:
    l_a,l_b,s_a,s_b = l[i[0]-1],l[i[1]-1],s[l[i[0]-1]],s[l[i[1]-1]]
    
    if s_a <= s_b:
      c = s_a*s_b
      s[l_b]+=s_a
      s[l_a]=0
      l[l==l_a]=l_b
      ans[m-2-k]=ans[m-1-k]-c
    else:
      c = s_a*s_b
      s[l_a]+=s_b
      s[l_b]=0
      l[l==l_b]=l_a
      ans[m-2-k]=ans[m-1-k]-c
  if ans[-1]==0:
    break
for i in ans:
  print(i)

Fixed submission:
n,m = map(int,input().split())
ab = [[int(i) for i in input().split()]for j in range(m)][1:]
ans = [0]*(m-1)+[int(n*(n-1)/2)]
l = [i for i in range(1,n+1)]
s = {i:1 for i in range(1,n+1)}
 
def serch_l(num):
  if l[num]==num+1:
    return l[num]
  else:
    leader = serch_l(l[num]-1)
    l[num]=leader
    return leader
    
for k,i in enumerate(ab[::-1]):
  k = m-1-k
  l_a,l_b = serch_l(i[0]-1),serch_l(i[1]-1)
  if l_a==l_b:
    ans[k-1]=ans[k]
  else:
    
    s_a,s_b = s[l_a],s[l_b]
    
    if s_a > s_b:
      (s_a,s_b) = (s_b,s_a)
      (l_a,l_b) = (l_b,l_a)
    c = s_a*s_b
    s[l_b]+=s_a
    s[l_a]=0
    l[l_a-1]=l_b
    ans[k-1]=ans[k]-c
for i in ans:
  print(i)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n,m = map(int,input().split())
ab = [[int(i) for i in input().split()]for j in range(m)][1:]

ans = [0]*(m-1)+[int(n*(n-1)/2)]
l = np.array([i for i in range(1,n+1)])
s = {i:1 for i in range(1,n+1)}
for k,i in enumerate(ab[::-1]):
  
  if l[i[0]-1] == l[i[1]-1]:
    ans[m-2-k]=ans[m-1-k]
  else:
    l_a,l_b,s_a,s_b = l[i[0]-1],l[i[1]-1],s[l[i[0]-1]],s[l[i[1]-1]]
    
    if l_a <= l_b:
      c = s_a*s_b
      s[l_b]+=s_a
      s[l_a]=0
      l[l==l_a]=l_b
      ans[m-2-k]=ans[m-1-k]-c
    else:
      c = s_a*s_b
      s[l_a]+=s_b
      s[l_b]=0
      l[l==l_b]=l_a
      ans[m-2-k]=ans[m-1-k]-c
  if ans[-1]==0:
    break
for i in ans:
  print(i)

Fixed submission:
n,m = map(int,input().split())
ab = [[int(i) for i in input().split()]for j in range(m)][1:]
ans = [0]*(m-1)+[int(n*(n-1)/2)]
l = [i for i in range(1,n+1)]
s = {i:1 for i in range(1,n+1)}
 
def serch_l(num):
  if l[num]==num+1:
    return l[num]
  else:
    leader = serch_l(l[num]-1)
    l[num]=leader
    return leader
    
for k,i in enumerate(ab[::-1]):
  k = m-1-k
  l_a,l_b = serch_l(i[0]-1),serch_l(i[1]-1)
  if l_a==l_b:
    ans[k-1]=ans[k]
  else:
    
    s_a,s_b = s[l_a],s[l_b]
    
    if s_a > s_b:
      (s_a,s_b) = (s_b,s_a)
      (l_a,l_b) = (l_b,l_a)
    c = s_a*s_b
    s[l_b]+=s_a
    s[l_a]=0
    l[l_a-1]=l_b
    ans[k-1]=ans[k]-c
for i in ans:
  print(i)