import sys
sys.setrecursionlimit(10**6)
n, m = map(int, input().split())
ab = []
for _ in range(m):
    a, b = map(int, input().split())
    ab.append((a-1, b-1))

class UnionFind():
    def __init__(self, li):
        self.li = li
        self.cnt = [1]*len(li)
        self.ans = 0
    def root(self, x):
        if self.li[x]==x:
            return x
        self.li[x] = self.root(self.li[x])
        return self.li[x]
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx==ry:
            return self.ans
        self.li[ry] = rx
        self.ans -= self.cnt[rx]*(self.cnt[rx]-1)//2
        self.ans -= self.cnt[ry]*(self.cnt[ry]-1)//2
        self.cnt[rx] += self.cnt[ry]
        self.ans += self.cnt[rx]*(self.cnt[rx]-1)//2
        return self.ans
uf = UnionFind(list(range(n)))
ans = [n*(n-1)//2]
for a, b in ab[::-1][:-1]:
    ans.append(n*(n-1)//2-uf.unite(a, b))
for i in reversed(ans):
    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 ab = [] ab [] for _ in range(m):
    a, b = map(int, input().split())
    ab.append((a-1, b-1)) _ range(m) range m a, b = map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b ab.append((a-1, b-1)) ab.append ab append (a-1, b-1) a-1 a 1 b-1 b 1 class UnionFind():
    def __init__(self, li):
        self.li = li
        self.cnt = [1]*len(li)
        self.ans = 0
    def root(self, x):
        if self.li[x]==x:
            return x
        self.li[x] = self.root(self.li[x])
        return self.li[x]
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx==ry:
            return self.ans
        self.li[ry] = rx
        self.ans -= self.cnt[rx]*(self.cnt[rx]-1)//2
        self.ans -= self.cnt[ry]*(self.cnt[ry]-1)//2
        self.cnt[rx] += self.cnt[ry]
        self.ans += self.cnt[rx]*(self.cnt[rx]-1)//2
        return self.ans UnionFind def __init__(self, li):
        self.li = li
        self.cnt = [1]*len(li)
        self.ans = 0
     __init__ self.li = li self.li self li li self.cnt = [1]*len(li) self.cnt self cnt [1]*len(li) [1] 1 len(li) len li self.ans = 0 self.ans self ans 0 self self li li def root(self, x):
        if self.li[x]==x:
            return x
        self.li[x] = self.root(self.li[x])
        return self.li[x]
     root if self.li[x]==x:
            return x
         self.li[x]==x self.li[x] self.li self li x x return x x self.li[x] = self.root(self.li[x]) self.li[x] self.li self li x self.root(self.li[x]) self.root self root self.li[x] self.li self li x return self.li[x] self.li[x] self.li self li x self self x x def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx==ry:
            return self.ans
        self.li[ry] = rx
        self.ans -= self.cnt[rx]*(self.cnt[rx]-1)//2
        self.ans -= self.cnt[ry]*(self.cnt[ry]-1)//2
        self.cnt[rx] += self.cnt[ry]
        self.ans += self.cnt[rx]*(self.cnt[rx]-1)//2
        return self.ans unite rx = self.root(x) rx self.root(x) self.root self root x ry = self.root(y) ry self.root(y) self.root self root y if rx==ry:
            return self.ans
         rx==ry rx ry return self.ans self.ans self ans self.li[ry] = rx self.li[ry] self.li self li ry rx self.ans -= self.cnt[rx]*(self.cnt[rx]-1)//2 self.ans self ans self.cnt[rx]*(self.cnt[rx]-1)//2 self.cnt[rx]*(self.cnt[rx]-1) self.cnt[rx] self.cnt self cnt rx self.cnt[rx]-1 self.cnt[rx] self.cnt self cnt rx 1 2 self.ans -= self.cnt[ry]*(self.cnt[ry]-1)//2 self.ans self ans self.cnt[ry]*(self.cnt[ry]-1)//2 self.cnt[ry]*(self.cnt[ry]-1) self.cnt[ry] self.cnt self cnt ry self.cnt[ry]-1 self.cnt[ry] self.cnt self cnt ry 1 2 self.cnt[rx] += self.cnt[ry] self.cnt[rx] self.cnt self cnt rx self.cnt[ry] self.cnt self cnt ry self.ans += self.cnt[rx]*(self.cnt[rx]-1)//2 self.ans self ans self.cnt[rx]*(self.cnt[rx]-1)//2 self.cnt[rx]*(self.cnt[rx]-1) self.cnt[rx] self.cnt self cnt rx self.cnt[rx]-1 self.cnt[rx] self.cnt self cnt rx 1 2 return self.ans self.ans self ans self self x x y y uf = UnionFind(list(range(n))) uf UnionFind(list(range(n))) UnionFind list(range(n)) list range(n) range n ans = [n*(n-1)//2] ans [n*(n-1)//2] n*(n-1)//2 n*(n-1) n n-1 n 1 2 for a, b in ab[::-1][:-1]:
    ans.append(n*(n-1)//2-uf.unite(a, b)) a b ab[::-1][:-1] [::-1] ab ::-1 -1 :-1 -1 ans.append(n*(n-1)//2-uf.unite(a, b)) ans.append ans append n*(n-1)//2-uf.unite(a, b) n*(n-1)//2 n*(n-1) n n-1 n 1 2 uf.unite(a, b) uf.unite uf unite a b for i in reversed(ans):
    print(i) i reversed(ans) reversed ans print(i) print i a, b = map(int, input().split()) map(int, input().split()) a class UnionFind():
    def __init__(self, li):
        self.li = li
        self.cnt = [1]*len(li)
        self.ans = 0
    def root(self, x):
        if self.li[x]==x:
            return x
        self.li[x] = self.root(self.li[x])
        return self.li[x]
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx==ry:
            return self.ans
        self.li[ry] = rx
        self.ans -= self.cnt[rx]*(self.cnt[rx]-1)//2
        self.ans -= self.cnt[ry]*(self.cnt[ry]-1)//2
        self.cnt[rx] += self.cnt[ry]
        self.ans += self.cnt[rx]*(self.cnt[rx]-1)//2
        return self.ans class UnionFind():
    def __init__(self, li):
        self.li = li
        self.cnt = [1]*len(li)
        self.ans = 0
    def root(self, x):
        if self.li[x]==x:
            return x
        self.li[x] = self.root(self.li[x])
        return self.li[x]
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx==ry:
            return self.ans
        self.li[ry] = rx
        self.ans -= self.cnt[rx]*(self.cnt[rx]-1)//2
        self.ans -= self.cnt[ry]*(self.cnt[ry]-1)//2
        self.cnt[rx] += self.cnt[ry]
        self.ans += self.cnt[rx]*(self.cnt[rx]-1)//2
        return self.ans UnionFind m = map(int, input().split()) map(int, input().split()) m ans = [n*(n-1)//2] [n*(n-1)//2] ans uf = UnionFind(list(range(n))) UnionFind(list(range(n))) uf ab = [] [] ab n, m = map(int, input().split()) map(int, input().split()) n b = map(int, input().split()) map(int, input().split()) b
import sys
sys.setrecursionlimit(10**6)
n, m = map(int, input().split())
ab = []
for _ in range(m):
    a, b = map(int, input().split())
    ab.append((a-1, b-1))

class UnionFind():
    def __init__(self, li):
        self.li = li
        self.cnt = [1]*len(li)
        self.ans = 0
    def root(self, x):
        if self.li[x]==x:
            return x
        self.li[x] = self.root(self.li[x])
        return self.li[x]
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx==ry:
            return self.ans
        self.li[ry] = rx
        self.ans -= self.cnt[rx]*(self.cnt[rx]-1)//2
        self.ans -= self.cnt[ry]*(self.cnt[ry]-1)//2
        self.cnt[rx] += self.cnt[ry]
        self.ans += self.cnt[rx]*(self.cnt[rx]-1)//2
        return self.ans
uf = UnionFind(list(range(n)))
ans = [n*(n-1)//2]
for a, b in ab[::-1][:-1]:
    ans.append(n*(n-1)//2-uf.unite(a, b))
for i in reversed(ans):
    print(i)