Buggy python submission (verdict: Time Limit Exceeded):
import collections
class UnionFind:
    def __init__(self, n):
        self.par =[i for i in range(n+1)]
        self.rank = [0] * (n+1)
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
#decayed briges
n,m=map(int,input().split())
lists=[0 for i  in range(m)]

Alists=[]
Alists.append(n*(n-1)//2)
for i in range(m):
    a,b=map(int,input().split())
    lists[i]=(a,b)
A=UnionFind(n)
lists=lists[::-1]
c=n*(n-1)//2
Alist=[]
for j in lists:
    a,b=j[0],j[1]
    par=dict(collections.Counter(A.par))
    if A.find(a)!=A.find(b):
        c-=(par[A.find(a)]*par[A.find(b)])
    else:
        pass
    A.union(a,b)
    for _ in range(n+1):
      A.find(_)
    Alists.append(c)
Alists=Alists[::-1]
for k in Alists[1:]:
    print(k)



Fixed submission:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * (n+1)
        
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return
        
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]
        
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


class UnionFindLabel(UnionFind):
    def __init__(self, labels):
        assert len(labels) == len(set(labels))
        
        self.n = len(labels)
        self.parents = [-1] * self.n
        self.d = {x: i for i, x in enumerate(labels)}
        self.d_inv = {i: x for i, x in enumerate(labels)}
    
    def find_label(self, x):
        return self.d_inv[super().find(self.d[x])]
    
    def union(self, x, y):
        super().union(self.d[x], self.d[y])
    
    def size(self, x):
        return super().size(self.d[x])
    
    def same(self, x, y):
        return super().same(self.d[x], self.d[y])
    
    def members(self, x):
        root = self.find(self.d[x])
        return [self.d_inv[i] for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [self.d_inv[i] for i, x in enumerate(self.parents) if x < 0]
#decayed briges
n,m=map(int,input().split())
lists=[0 for i  in range(m)]
Alists=[]
Alists.append(n*(n-1)//2)
for i in range(m):
    #計算量O(M)
    a,b=map(int,input().split())
    lists[i]=(a,b)
A=UnionFind(n)
lists=lists[::-1]
c=n*(n-1)//2
Alist=[]
for j in lists:
    a,b=j[0],j[1]
    if A.find(a)!=A.find(b):
        c=c-A.size(a)*A.size(b)
        A.union(a,b)
    Alists.append(c)
Alists=Alists[::-1]
for k in Alists[1:]:
    print(k)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
class UnionFind:
    def __init__(self, n):
        self.par =[i for i in range(n+1)]
        self.rank = [0] * (n+1)
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
#decayed briges
n,m=map(int,input().split())
lists=[0 for i  in range(m)]
Huben=[0 for i in range(m)]
Alists=[]
Alists.append(n*(n-1)//2)
for i in range(m):
    a,b=map(int,input().split())
    lists[i]=(a,b)
A=UnionFind(n)
lists=lists[::-1]
for j in lists:
    a,b=j[0],j[1]
    A.union(a,b)
    for _ in range(1,n+1):
      A.find(_)
    par=dict(collections.Counter(A.par))
    del par[0]
    alone=0
    c=0
    d=0
    for j in par.values():
      if j!=1:
        c+=(j)
        d+=(j**2)
      elif j==1:
        alone+=1
    huben=(c**2-d)//2+(alone*(alone-1))//2+alone*(n-alone)
    Alists.append(huben)

Alists=Alists[::-1]
for k in Alists[1:]:
    print(k)


Fixed submission:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * (n+1)
        
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return
        
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]
        
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


class UnionFindLabel(UnionFind):
    def __init__(self, labels):
        assert len(labels) == len(set(labels))
        
        self.n = len(labels)
        self.parents = [-1] * self.n
        self.d = {x: i for i, x in enumerate(labels)}
        self.d_inv = {i: x for i, x in enumerate(labels)}
    
    def find_label(self, x):
        return self.d_inv[super().find(self.d[x])]
    
    def union(self, x, y):
        super().union(self.d[x], self.d[y])
    
    def size(self, x):
        return super().size(self.d[x])
    
    def same(self, x, y):
        return super().same(self.d[x], self.d[y])
    
    def members(self, x):
        root = self.find(self.d[x])
        return [self.d_inv[i] for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [self.d_inv[i] for i, x in enumerate(self.parents) if x < 0]
#decayed briges
n,m=map(int,input().split())
lists=[0 for i  in range(m)]
Alists=[]
Alists.append(n*(n-1)//2)
for i in range(m):
    #計算量O(M)
    a,b=map(int,input().split())
    lists[i]=(a,b)
A=UnionFind(n)
lists=lists[::-1]
c=n*(n-1)//2
Alist=[]
for j in lists:
    a,b=j[0],j[1]
    if A.find(a)!=A.find(b):
        c=c-A.size(a)*A.size(b)
        A.union(a,b)
    Alists.append(c)
Alists=Alists[::-1]
for k in Alists[1:]:
    print(k)