Buggy python submission (verdict: Time Limit Exceeded):
class UnionFind():
  def __init__(self, n):
    self.n=n
    self.p=[-1]*n

  def find(self,x):
    if self.p[x]<0:
      return x
    else:
      self.p[x]=self.find(self.p[x])
    return self.p[x]

  def same(self,x,y):
    return self.find(x)==self.find(y)

  def unite(self,x,y):
    x = self.find(x)
    y = self.find(y)
    if x==y:
      return

    if self.p[x]>self.p[y]:
      x,y=y,x

    self.p[x] += self.p[y]
    self.p[y] = x

  def members(self,x):
    p = self.find(x)
    return [i for i in range(self.n) if self.find(i)==p]

  def roots(self):
    return [i for i,x in enumerate(self.p) if x<0]

  def gcount(self):
    return len(self.roots())
 
  def uprint(self):
    print(self.p)
    return

n,m=map(int,input().split())
b=[[int(x) for x in input().split()] for y in range(m)]
u=n*(n-1)//2

s=[]
a=[u]
uf=UnionFind(n)

for i in range(m-1,0,-1):
  uf.unite(b[i][0]-1,b[i][1]-1)
  t = 0
  for j in uf.roots():
    n = len(uf.members(j))
    t += (n * (n-1)) // 2
  a.append(u-t)

a.reverse()
for i in range(len(a)):
  print(a[i])


Fixed submission:
n, m = map(int, input().split())
e = [[int(x) for x in input().split()] for _ in range(m)]

u = [-1]*(n+1)

def find(x):
  return x if u[x] < 0 else find(u[x])

t = n*(n-1)// 2
s = [t]

for i in range(m-1,0,-1):
  a = find(e[i][0])
  b = find(e[i][1])
  if a > b:
    a, b = b, a
  if a != b:
    t -= u[a]*u[b]
    u[a] += u[b]
    u[b] = a
  s.append(t)

for i in reversed(s):
  print(i)

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
b=[[int(x) for x in input().split()] for y in range(m)]
u=n*(n-1)//2

s=set()
a=[u]

for i in range(m-1,0,-1):
  x=y=-1
  for j in range(len(s)):
    if b[i][0] in s[j]:
      x = j
    if b[i][1] in s[j]:
      y = j
    if x!=-1 and y!=-1:
      break

  if x==-1 and y==-1:
    s.append(set((b[i][0],b[i][1])))
  elif y==-1:
    s[x].add(b[i][1])
  elif x==-1:
    s[y].add(b[i][0])
  elif x!=y:
    for k in range(len(s[y])):
      s[x].add(s[y].pop())
    s.pop(y)

  t=0
  for j in range(len(s)):
    t += (len(s[j])*(len(s[j])-1))//2
  a.append(u-t)
 
a.reverse()
for i in range(len(a)):
  print(a[i])


Fixed submission:
n, m = map(int, input().split())
e = [[int(x) for x in input().split()] for _ in range(m)]

u = [-1]*(n+1)

def find(x):
  return x if u[x] < 0 else find(u[x])

t = n*(n-1)// 2
s = [t]

for i in range(m-1,0,-1):
  a = find(e[i][0])
  b = find(e[i][1])
  if a > b:
    a, b = b, a
  if a != b:
    t -= u[a]*u[b]
    u[a] += u[b]
    u[b] = a
  s.append(t)

for i in reversed(s):
  print(i)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
b=[[int(x) for x in input().split()] for y in range(m)]
u=n*(n-1)//2

s=[]
a=[u]

for i in range(m-1,0,-1):
  x=y=-1
  for j in range(len(s)):
    if b[i][0] in s[j]:
      x = j
    if b[i][1] in s[j]:
      y = j
    if x!=-1 and y!=-1:
      break

  if x==-1 and y==-1:
    s.append(set((b[i][0],b[i][1])))
  elif y==-1:
    s[x].add(b[i][1])
  elif x==-1:
    s[y].add(b[i][0])
  elif x!=y:
    for k in range(len(s[y])):
      s[x].add(s[y].pop())
    s.pop(y)

  t=0
  for j in range(len(s)):
    t += (len(s[j])*(len(s[j])-1))//2
  a.append(u-t)
 
a.reverse()
for i in range(len(a)):
  print(a[i])


Fixed submission:
n, m = map(int, input().split())
e = [[int(x) for x in input().split()] for _ in range(m)]

u = [-1]*(n+1)

def find(x):
  return x if u[x] < 0 else find(u[x])

t = n*(n-1)// 2
s = [t]

for i in range(m-1,0,-1):
  a = find(e[i][0])
  b = find(e[i][1])
  if a > b:
    a, b = b, a
  if a != b:
    t -= u[a]*u[b]
    u[a] += u[b]
    u[b] = a
  s.append(t)

for i in reversed(s):
  print(i)