Buggy python submission (verdict: Time Limit Exceeded):
n,m = [int(i) for i in input().split()]
ab = []
for i in range(m):
  ab.append([int(i)-1 for i in input().split()])

def find_index(c,eld):
  if c in eld[c]:
    return(c,len(eld[c]))
  else:
    return(eld[c][0],len(eld[eld[c][0]]))
           
eld = []
for i in range(n):
  eld.append([i])
stat = eld
ans = [int(len(eld)*(len(eld)-1)/2)]

for a,b in ab[1:][::-1]:
#  print(eld)
  a_index,a_size = find_index(a,eld)
  b_index,b_size = find_index(b,eld)
#  print(a_index,b_index)
  if a_index == b_index:
    ans.append(ans[-1])
    continue
  else:
    next = a_size * b_size
    ans.append(ans[-1] - next)

  if a_size >= b_size:
    eld[a_index].extend(eld[b_index])
    for i in eld[a_index][1:]:
      eld[i] = [a_index]
  else:
    eld[b_index].extend(eld[a_index])
    for i in eld[b_index][1:]:
      eld[i] = [b_index]

for i in ans[::-1]:
  print(i)

Fixed submission:
n,m = [int(i) for i in input().split()]
ab = []
for i in range(m):
  ab.append([int(i)-1 for i in input().split()])

def find_index(c,eld):
  if c in eld[c]:
    return(c,len(eld[c]))
  else:
    return(eld[c][0],len(eld[eld[c][0]]))
           
eld = []
for i in range(n):
  eld.append([i])
stat = eld
ans = [int(len(eld)*(len(eld)-1)/2)]

for a,b in ab[1:][::-1]:
#  print(eld)
  a_index,a_size = find_index(a,eld)
  b_index,b_size = find_index(b,eld)
#  print(a_index,b_index)
  if a_index == b_index:
    ans.append(ans[-1])
    continue
  else:
    next = a_size * b_size
    ans.append(ans[-1] - next)

  if a_size >= b_size:
    eld[a_index].extend(eld[b_index])
    for i in eld[b_index]:
      eld[i] = [a_index]
  else:
    eld[b_index].extend(eld[a_index])
    for i in eld[a_index]:
      eld[i] = [b_index]

for i in ans[::-1]:
  print(i)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = [int(i) for i in input().split()]
ab = []
for i in range(m):
  ab.append([int(i)-1 for i in input().split()])

def find_index(c,eld):
  for i in range(len(eld)):
    if c in eld[i]:
      index = i
      size = len(eld[i])
      return(index,size)
    
eld = []
for i in range(n):
  eld.append([i])
ans = [int(len(eld)*(len(eld)-1)/2)]

for a,b in ab[1:][::-1]:
  a_index,a_size = find_index(a,eld)
  b_index,b_size = find_index(b,eld)
  if a_index == b_index:
    ans.append(ans[-1])
    continue
  if a_size >= b_size:
    eld[a_index].extend(eld[b_index])
    del eld[b_index]
  else:
    eld[b_index].extend(eld[a_index])
    del eld[a_index]
    
  eld_len = len(eld)
  num = 0
  for i in range(eld_len):
    num += len(eld[i]) * (n-len(eld[i]))
  num = int(num/2)
  ans.append(num)

for i in ans[::-1]:
  print(i)


  

Fixed submission:
n,m = [int(i) for i in input().split()]
ab = []
for i in range(m):
  ab.append([int(i)-1 for i in input().split()])

def find_index(c,eld):
  if c in eld[c]:
    return(c,len(eld[c]))
  else:
    return(eld[c][0],len(eld[eld[c][0]]))
           
eld = []
for i in range(n):
  eld.append([i])
stat = eld
ans = [int(len(eld)*(len(eld)-1)/2)]

for a,b in ab[1:][::-1]:
#  print(eld)
  a_index,a_size = find_index(a,eld)
  b_index,b_size = find_index(b,eld)
#  print(a_index,b_index)
  if a_index == b_index:
    ans.append(ans[-1])
    continue
  else:
    next = a_size * b_size
    ans.append(ans[-1] - next)

  if a_size >= b_size:
    eld[a_index].extend(eld[b_index])
    for i in eld[b_index]:
      eld[i] = [a_index]
  else:
    eld[b_index].extend(eld[a_index])
    for i in eld[a_index]:
      eld[i] = [b_index]

for i in ans[::-1]:
  print(i)

Buggy python submission (verdict: Runtime Error):
import numpy as np

n,m = [int(i) for i in input().split()]

keiro = np.eye(n)
ab = []
for i in range(m):
  a,b = [int(i)-1 for i in input().split()]
  ab.append([a, b])
  keiro[a,b] = 1
  keiro[b,a] = 1

for i in range(m):
  cnt = 0
  a,b = ab[i]
  keiro[a,b] = 0
  keiro[b,a] = 0
  
  eig, p = np.linalg.eig(keiro)
  p_inv = np.linalg.inv(p)
  eig = eig**(m-i-1)
  d = np.diag(eig)
  keiro_tmp = np.dot(p,d)
  keiro_tmp = np.dot(keiro_tmp,p_inv)
  cnt = int(np.sum(keiro_tmp == 0) / 2)
  print(cnt)

Fixed submission:
n,m = [int(i) for i in input().split()]
ab = []
for i in range(m):
  ab.append([int(i)-1 for i in input().split()])

def find_index(c,eld):
  if c in eld[c]:
    return(c,len(eld[c]))
  else:
    return(eld[c][0],len(eld[eld[c][0]]))
           
eld = []
for i in range(n):
  eld.append([i])
stat = eld
ans = [int(len(eld)*(len(eld)-1)/2)]

for a,b in ab[1:][::-1]:
#  print(eld)
  a_index,a_size = find_index(a,eld)
  b_index,b_size = find_index(b,eld)
#  print(a_index,b_index)
  if a_index == b_index:
    ans.append(ans[-1])
    continue
  else:
    next = a_size * b_size
    ans.append(ans[-1] - next)

  if a_size >= b_size:
    eld[a_index].extend(eld[b_index])
    for i in eld[b_index]:
      eld[i] = [a_index]
  else:
    eld[b_index].extend(eld[a_index])
    for i in eld[a_index]:
      eld[i] = [b_index]

for i in ans[::-1]:
  print(i)

Buggy python submission (verdict: Runtime Error):
import numpy as np

n,m = [int(i) for i in input().split()]

keiro = np.eye(n)
ab = []
for i in range(m):
  a,b = [int(i)-1 for i in input().split()]
  ab.append([a, b])
  keiro[a,b] = 1
  keiro[b,a] = 1

for i in range(m):
  cnt = 0
  a,b = ab[i]
  keiro[a,b] = 0
  keiro[b,a] = 0
  
  eig, p = np.linalg.eig(keiro)
  p_inv = np.linalg.inv(p)
  eig = eig**(m-i-1)
  d = np.diag(eig)
  keiro_tmp = np.dot(p,d)
  keiro_tmp = np.dot(keiro_tmp,p_inv)
  cnt = np.sum(keiro_tmp == 0) / 2
  print(cnt)

Fixed submission:
n,m = [int(i) for i in input().split()]
ab = []
for i in range(m):
  ab.append([int(i)-1 for i in input().split()])

def find_index(c,eld):
  if c in eld[c]:
    return(c,len(eld[c]))
  else:
    return(eld[c][0],len(eld[eld[c][0]]))
           
eld = []
for i in range(n):
  eld.append([i])
stat = eld
ans = [int(len(eld)*(len(eld)-1)/2)]

for a,b in ab[1:][::-1]:
#  print(eld)
  a_index,a_size = find_index(a,eld)
  b_index,b_size = find_index(b,eld)
#  print(a_index,b_index)
  if a_index == b_index:
    ans.append(ans[-1])
    continue
  else:
    next = a_size * b_size
    ans.append(ans[-1] - next)

  if a_size >= b_size:
    eld[a_index].extend(eld[b_index])
    for i in eld[b_index]:
      eld[i] = [a_index]
  else:
    eld[b_index].extend(eld[a_index])
    for i in eld[a_index]:
      eld[i] = [b_index]

for i in ans[::-1]:
  print(i)

Buggy python submission (verdict: Runtime Error):
import numpy as np

n,m = [int(i) for i in input().split()]

keiro = np.eye(n)
ab = []
for i in range(m):
  a,b = [int(i)-1 for i in input().split()]
  ab.append([a, b])
  keiro[a,b] = 1
  keiro[b,a] = 1

cnt = []
for i in range(m):
  cnt = 0
  a,b = ab[i]
  keiro[a,b] = 0
  keiro[b,a] = 0
  
  eig, p = np.linalg.eig(keiro)
  p_inv = np.linalg.inv(p)
  eig = eig**(m-i-1)
  d = np.diag(eig)
  keiro_tmp = np.dot(p,d)
  keiro_tmp = np.dot(keiro_tmp,p_inv)
  for j in range(0,n-1):
    for k in range(j+1,n):
      if keiro_tmp[j,k] == 0:
        cnt += 1
  print(cnt)

Fixed submission:
n,m = [int(i) for i in input().split()]
ab = []
for i in range(m):
  ab.append([int(i)-1 for i in input().split()])

def find_index(c,eld):
  if c in eld[c]:
    return(c,len(eld[c]))
  else:
    return(eld[c][0],len(eld[eld[c][0]]))
           
eld = []
for i in range(n):
  eld.append([i])
stat = eld
ans = [int(len(eld)*(len(eld)-1)/2)]

for a,b in ab[1:][::-1]:
#  print(eld)
  a_index,a_size = find_index(a,eld)
  b_index,b_size = find_index(b,eld)
#  print(a_index,b_index)
  if a_index == b_index:
    ans.append(ans[-1])
    continue
  else:
    next = a_size * b_size
    ans.append(ans[-1] - next)

  if a_size >= b_size:
    eld[a_index].extend(eld[b_index])
    for i in eld[b_index]:
      eld[i] = [a_index]
  else:
    eld[b_index].extend(eld[a_index])
    for i in eld[a_index]:
      eld[i] = [b_index]

for i in ans[::-1]:
  print(i)

Buggy python submission (verdict: Runtime Error):
import numpy as np

n,m = [int(i) for i in input().split()]

keiro = np.eye(n)
ab = []
for i in range(m):
  a,b = [int(i)-1 for i in input().split()]
  ab.append([a, b])
  keiro[a,b] = 1
  keiro[b,a] = 1
cnt = []
for i in range(m):
  cnt_i = 0
  a,b = ab[i]
  keiro[a,b] = 0
  keiro[b,a] = 0
  keiro_tmp = keiro.copy()
  for j in range(m-i-1):
    keiro_tmp = np.dot(keiro_tmp,keiro_tmp)
  for j in range(0,n-1):
    for k in range(j+1,n):
      if keiro_tmp[j,k] == 0:
        cnt_i += 1
  cnt.append(cnt_i)
for i in range(m):
  print(cnt[i])

Fixed submission:
n,m = [int(i) for i in input().split()]
ab = []
for i in range(m):
  ab.append([int(i)-1 for i in input().split()])

def find_index(c,eld):
  if c in eld[c]:
    return(c,len(eld[c]))
  else:
    return(eld[c][0],len(eld[eld[c][0]]))
           
eld = []
for i in range(n):
  eld.append([i])
stat = eld
ans = [int(len(eld)*(len(eld)-1)/2)]

for a,b in ab[1:][::-1]:
#  print(eld)
  a_index,a_size = find_index(a,eld)
  b_index,b_size = find_index(b,eld)
#  print(a_index,b_index)
  if a_index == b_index:
    ans.append(ans[-1])
    continue
  else:
    next = a_size * b_size
    ans.append(ans[-1] - next)

  if a_size >= b_size:
    eld[a_index].extend(eld[b_index])
    for i in eld[b_index]:
      eld[i] = [a_index]
  else:
    eld[b_index].extend(eld[a_index])
    for i in eld[a_index]:
      eld[i] = [b_index]

for i in ans[::-1]:
  print(i)