N, M = map(int, input().split())
Edge = []
for i in range(M):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    Edge.append([a, b])


class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * n
        self.size = [1] * n

    # 検索
    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 x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
            self.size[x] = 0
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            self.size[y] = 0
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # すべての頂点に対して親を検索する
    def all_find(self):
        for n in range(len(self.par)):
            self.find(n)


UF = UnionFind(N)
Score = N * (N - 1) // 2
ans = []
while Edge:
    ans.append(Score)
    a, b = Edge.pop()
    pa, pb = UF.find(a), UF.find(b)
    if not UF.same(pa, pb):
        Score -= (UF.size[pa] * UF.size[pb])
    UF.union(a, b)

print(*ans[::-1], sep='\n') N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M Edge = [] Edge [] for i in range(M):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    Edge.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 a, b = a - 1, b - 1 a a - 1 a 1 b b - 1 b 1 Edge.append([a, b]) Edge.append Edge append [a, b] a b class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * n
        self.size = [1] * n

    # 検索
    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 x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
            self.size[x] = 0
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            self.size[y] = 0
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # すべての頂点に対して親を検索する
    def all_find(self):
        for n in range(len(self.par)):
            self.find(n) UnionFind def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * n
        self.size = [1] * n

    # 検索
     __init__ i for i in range(n) for i in range(n) i range(n) range n for i in range(n) i self.par = [i for i in range(n)] self.par self par [i for i in range(n)] self.rank = [0] * n self.rank self rank [0] * n [0] 0 n self.size = [1] * n self.size self size [1] * n [1] 1 n self self n n def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
     find if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
     self.par[x] == x self.par[x] self.par self par x x return x x self.par[x] = self.find(self.par[x]) self.par[x] self.par self par x self.find(self.par[x]) self.find self find self.par[x] self.par self par x return self.par[x] self.par[x] self.par self par x self self x x def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
            self.size[x] = 0
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            self.size[y] = 0
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
     union x = self.find(x) x self.find(x) self.find self find x y = self.find(y) y self.find(y) self.find self find y if x == y:
            return

         x == y x y return if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
            self.size[x] = 0
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            self.size[y] = 0
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
     self.rank[x] < self.rank[y] self.rank[x] self.rank self rank x self.rank[y] self.rank self rank y self.par[x] = y self.par[x] self.par self par x y self.size[y] += self.size[x] self.size[y] self.size self size y self.size[x] self.size self size x self.size[x] = 0 self.size[x] self.size self size x 0 self.par[y] = x self.par[y] self.par self par y x self.size[x] += self.size[y] self.size[x] self.size self size x self.size[y] self.size self size y self.size[y] = 0 self.size[y] self.size self size y 0 if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
     self.rank[x] == self.rank[y] self.rank[x] self.rank self rank x self.rank[y] self.rank self rank y self.rank[x] += 1 self.rank[x] self.rank self rank x 1 self self x x y y def same(self, x, y):
        return self.find(x) == self.find(y)

    # すべての頂点に対して親を検索する
     same return self.find(x) == self.find(y) self.find(x) == self.find(y) self.find(x) self.find self find x self.find(y) self.find self find y self self x x y y def all_find(self):
        for n in range(len(self.par)):
            self.find(n) all_find for n in range(len(self.par)):
            self.find(n) n range(len(self.par)) range len(self.par) len self.par self par self.find(n) self.find self find n self self UF = UnionFind(N) UF UnionFind(N) UnionFind N Score = N * (N - 1) // 2 Score N * (N - 1) // 2 N * (N - 1) N N - 1 N 1 2 ans = [] ans [] while Edge:
    ans.append(Score)
    a, b = Edge.pop()
    pa, pb = UF.find(a), UF.find(b)
    if not UF.same(pa, pb):
        Score -= (UF.size[pa] * UF.size[pb])
    UF.union(a, b) Edge ans.append(Score) ans.append ans append Score a, b = Edge.pop() a Edge.pop() Edge.pop Edge pop b pa, pb = UF.find(a), UF.find(b) pa UF.find(a) UF.find UF find a pb UF.find(b) UF.find UF find b if not UF.same(pa, pb):
        Score -= (UF.size[pa] * UF.size[pb])
     not UF.same(pa, pb) UF.same(pa, pb) UF.same UF same pa pb Score -= (UF.size[pa] * UF.size[pb]) Score UF.size[pa] * UF.size[pb] UF.size[pa] UF.size UF size pa UF.size[pb] UF.size UF size pb UF.union(a, b) UF.union UF union a b print(*ans[::-1], sep='\n') print *ans[::-1] ans[::-1] ans ::-1 -1 sep='\n' sep '\n' ans = [] [] ans a, b = map(int, input().split()) map(int, input().split()) a class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * n
        self.size = [1] * n

    # 検索
    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 x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
            self.size[x] = 0
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            self.size[y] = 0
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # すべての頂点に対して親を検索する
    def all_find(self):
        for n in range(len(self.par)):
            self.find(n) class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * n
        self.size = [1] * n

    # 検索
    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 x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
            self.size[x] = 0
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            self.size[y] = 0
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # すべての頂点に対して親を検索する
    def all_find(self):
        for n in range(len(self.par)):
            self.find(n) UnionFind a, b = a - 1, b - 1 a - 1 a pb = UF.find(a), UF.find(b) UF.find(b) pb N, M = map(int, input().split()) map(int, input().split()) N a, b = Edge.pop() Edge.pop() a Edge = [] [] Edge Score = N * (N - 1) // 2 N * (N - 1) // 2 Score b = map(int, input().split()) map(int, input().split()) b b = a - 1, b - 1 b - 1 b UF = UnionFind(N) UnionFind(N) UF b = Edge.pop() Edge.pop() b Score -= (UF.size[pa] * UF.size[pb]) UF.size[pa] * UF.size[pb] Score M = map(int, input().split()) map(int, input().split()) M pa, pb = UF.find(a), UF.find(b) UF.find(a) pa
N, M = map(int, input().split())
Edge = []
for i in range(M):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    Edge.append([a, b])


class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * n
        self.size = [1] * n

    # 検索
    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 x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
            self.size[x] = 0
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            self.size[y] = 0
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # すべての頂点に対して親を検索する
    def all_find(self):
        for n in range(len(self.par)):
            self.find(n)


UF = UnionFind(N)
Score = N * (N - 1) // 2
ans = []
while Edge:
    ans.append(Score)
    a, b = Edge.pop()
    pa, pb = UF.find(a), UF.find(b)
    if not UF.same(pa, pb):
        Score -= (UF.size[pa] * UF.size[pb])
    UF.union(a, b)

print(*ans[::-1], sep='\n')
