import sys
sys.setrecursionlimit(10 ** 6)
N,M=map(int,input().split())
bridge=[]
size=[1]*(N+1)
tree=list(range(N+1))
def find(a):
    x=tree[a]
    if a==x:
        return a
    x=find(x)
    tree[a]=x
    return x
for i in range(M):
    A,B=map(int,input().split())
    bridge.append((A,B))
Ans=N*(N-1)//2
ans=[]
for a,b in bridge[::-1]:
    aroot=find(a)
    broot=find(b)
    if aroot==broot:
        ans.append(Ans)
        continue
    ans.append(Ans)
    Ans-=size[aroot]*size[broot]
    tree[broot]=aroot
    size[aroot]+=size[broot]
for i in ans[::-1]:
    print(i) import sys sys sys.setrecursionlimit(10 ** 6) sys.setrecursionlimit sys setrecursionlimit 10 ** 6 10 6 N,M=map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M bridge=[] bridge [] size=[1]*(N+1) size [1]*(N+1) [1] 1 N+1 N 1 tree=list(range(N+1)) tree list(range(N+1)) list range(N+1) range N+1 N 1 def find(a):
    x=tree[a]
    if a==x:
        return a
    x=find(x)
    tree[a]=x
    return x find x=tree[a] x tree[a] tree a if a==x:
        return a
     a==x a x return a a x=find(x) x find(x) find x tree[a]=x tree[a] tree a x return x x a a for i in range(M):
    A,B=map(int,input().split())
    bridge.append((A,B)) i range(M) range M A,B=map(int,input().split()) A map(int,input().split()) map int input().split() ().split () input split B bridge.append((A,B)) bridge.append bridge append (A,B) A B Ans=N*(N-1)//2 Ans N*(N-1)//2 N*(N-1) N N-1 N 1 2 ans=[] ans [] for a,b in bridge[::-1]:
    aroot=find(a)
    broot=find(b)
    if aroot==broot:
        ans.append(Ans)
        continue
    ans.append(Ans)
    Ans-=size[aroot]*size[broot]
    tree[broot]=aroot
    size[aroot]+=size[broot] a b bridge[::-1] bridge ::-1 -1 aroot=find(a) aroot find(a) find a broot=find(b) broot find(b) find b if aroot==broot:
        ans.append(Ans)
        continue
     aroot==broot aroot broot ans.append(Ans) ans.append ans append Ans continue ans.append(Ans) ans.append ans append Ans Ans-=size[aroot]*size[broot] Ans size[aroot]*size[broot] size[aroot] size aroot size[broot] size broot tree[broot]=aroot tree[broot] tree broot aroot size[aroot]+=size[broot] size[aroot] size aroot size[broot] size broot for i in ans[::-1]:
    print(i) i ans[::-1] ans ::-1 -1 print(i) print i ans=[] [] ans Ans-=size[aroot]*size[broot] size[aroot]*size[broot] Ans B=map(int,input().split()) map(int,input().split()) B Ans=N*(N-1)//2 N*(N-1)//2 Ans M=map(int,input().split()) map(int,input().split()) M A,B=map(int,input().split()) map(int,input().split()) A aroot=find(a) find(a) aroot broot=find(b) find(b) broot size=[1]*(N+1) [1]*(N+1) size tree=list(range(N+1)) list(range(N+1)) tree bridge=[] [] bridge N,M=map(int,input().split()) map(int,input().split()) N def find(a):
    x=tree[a]
    if a==x:
        return a
    x=find(x)
    tree[a]=x
    return x def find(a):
    x=tree[a]
    if a==x:
        return a
    x=find(x)
    tree[a]=x
    return x find
import sys
sys.setrecursionlimit(10 ** 6)
N,M=map(int,input().split())
bridge=[]
size=[1]*(N+1)
tree=list(range(N+1))
def find(a):
    x=tree[a]
    if a==x:
        return a
    x=find(x)
    tree[a]=x
    return x
for i in range(M):
    A,B=map(int,input().split())
    bridge.append((A,B))
Ans=N*(N-1)//2
ans=[]
for a,b in bridge[::-1]:
    aroot=find(a)
    broot=find(b)
    if aroot==broot:
        ans.append(Ans)
        continue
    ans.append(Ans)
    Ans-=size[aroot]*size[broot]
    tree[broot]=aroot
    size[aroot]+=size[broot]
for i in ans[::-1]:
    print(i)