class UnionFind:

    def __init__(self, n):

        self.par = [-1 for i in range(n+1)]

        self.size = [1 for i in range(n+1)]

    # 検索

    def find(self, x):

        path = []

        curr = x

        # 親ノードの手前で止まる(どの根に紐づくかの情報を持ちながら)

        while self.par[curr] != -1:

            # 自分自身じゃない場合は、上にさかのぼって検索(再帰的に)

            path.append(curr)

            curr = self.par[curr]

        for p in path:

            self.par[p] = curr

        return curr



    # 結合

    def union(self, x, y):

        x = self.find(x)

        y = self.find(y)

        self.par[y] = x

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

        self.size[y] = 1



    # 判定

    def judge(self,x,y):

        return self.find(x) == self.find(y)



N, M = list(map(int,input().split()))

pairs = [tuple(map(int,input().split())) for _ in range(M)]

uf = UnionFind(N)

p = N*(N-1)//2

ans = [p]

for a,b in reversed(pairs[1:]):

    if not uf.judge(a,b):

        size_a = uf.size[uf.find(a)]

        size_b = uf.size[uf.find(b)]

        uf.union(a,b)

        size_a_update = uf.size[uf.find(a)]

        p = p + size_a*(size_a-1)//2 + size_b*(size_b-1)//2 - size_a_update*(size_a_update-1)//2



    ans.append(p)

for a in reversed(ans):

    print(a)



n, m = list(map(int, input().split()))

# 逆順にunionfind

from collections import defaultdict

class UnionFind:

    def __init__(self, n):

        class KeyDict(dict):

            # 辞書にないときの対応

            def __missing__(self,key):

                self[key] = key

                return key

        self.parent = KeyDict()

        self.rank = defaultdict(int)

        self.weight = defaultdict(lambda:1)



    # 根を探す

    def find(self, x):

        if self.parent[x] == x:

            return x

        else:

            # 経路圧縮

            # 自分自身じゃない場合は、上にさかのぼって検索(再帰的に)

            y = self.find(self.parent[x])

            self.parent[x] = y      #親の置き換え(圧縮)

            return self.parent[x]



    # 結合

    def union(self, x, y):

        x = self.find(x)

        y = self.find(y)

        # 低い方を高い方につなげる(親のランクによる)

        if self.rank[x] < self.rank[y]:

            self.parent[x] = y

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

            self.weight[x] = 0

        else:

            self.parent[y] = x

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

            self.weight[y] = 0

        

        if self.rank[x] == self.rank[y]:

            self.rank[x] += 1





    # 判定

    def judge(self, x, y):

        return self.find(x) == self.find(y)



ps = []

for i in range(m):

    a,b = list(map(int, input().split()))

    a -= 1

    b -= 1

    ps.append((a,b))



uf = UnionFind(n)

now = n*(n-1)//2

ans = [now]

for a, b in ps[::-1]:

    if not uf.judge(a,b):

        n1 = uf.weight[uf.find(a)]

        n2 = uf.weight[uf.find(b)]

        now += n1*(n1-1)//2 + n2*(n2-1)//2 - (n1+n2)*(n1+n2-1)//2

        uf.union(a,b)

    ans.append(now)



for a in ans[::-1][1:]:

    print(a)
class UnionFind:
    def __init__(self, n):
        self.par = [-1 for i in range(n + 1)]
        self.size = [1 for i in range(n + 1)]

    # 検索
    def find(self, x):
        path = []
        curr = x
        # 親ノードの手前で止まる(どの根に紐づくかの情報を持ちながら)
        while self.par[curr] != -1:
            # 自分自身じゃない場合は、上にさかのぼって検索(再帰的に)
            path.append(curr)
            curr = self.par[curr]
        for p in path:
            self.par[p] = curr
        return curr

    # 結合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        self.par[y] = x
        self.size[x] += self.size[y]
        self.size[y] = 1

    # 判定
    def judge(self, x, y):
        return self.find(x) == self.find(y)


N, M = list(map(int, input().split()))
pairs = [tuple(map(int, input().split())) for _ in range(M)]
uf = UnionFind(N)
p = N * (N - 1) // 2
ans = [p]
for a, b in reversed(pairs[1:]):
    if not uf.judge(a, b):
        size_a = uf.size[uf.find(a)]
        size_b = uf.size[uf.find(b)]
        uf.union(a, b)
        size_a_update = uf.size[uf.find(a)]
        p = (
            p
            + size_a * (size_a - 1) // 2
            + size_b * (size_b - 1) // 2
            - size_a_update * (size_a_update - 1) // 2
        )
    ans.append(p)
for a in reversed(ans):
    print(a)

n, m = list(map(int, input().split()))
# 逆順にunionfind
from collections import defaultdict


class UnionFind:
    def __init__(self, n):
        class KeyDict(dict):
            # 辞書にないときの対応
            def __missing__(self, key):
                self[key] = key
                return key

        self.parent = KeyDict()
        self.rank = defaultdict(int)
        self.weight = defaultdict(lambda: 1)

    # 根を探す
    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            # 経路圧縮
            # 自分自身じゃない場合は、上にさかのぼって検索(再帰的に)
            y = self.find(self.parent[x])
            self.parent[x] = y  # 親の置き換え(圧縮)
            return self.parent[x]

    # 結合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        # 低い方を高い方につなげる(親のランクによる)
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
            self.weight[y] += self.weight[x]
            self.weight[x] = 0
        else:
            self.parent[y] = x
            self.weight[x] += self.weight[y]
            self.weight[y] = 0
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1

    # 判定
    def judge(self, x, y):
        return self.find(x) == self.find(y)


ps = []
for i in range(m):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    ps.append((a, b))
uf = UnionFind(n)
now = n * (n - 1) // 2
ans = [now]
for a, b in ps[::-1]:
    if not uf.judge(a, b):
        n1 = uf.weight[uf.find(a)]
        n2 = uf.weight[uf.find(b)]
        now += n1 * (n1 - 1) // 2 + n2 * (n2 - 1) // 2 - (n1 + n2) * (n1 + n2 - 1) // 2
        uf.union(a, b)
    ans.append(now)
for a in ans[::-1][1:]:
    print(a)

+n, m = list(map(int, input().split())) +# 逆順にunionfind +from collections import defaultdict + + -        self.par = [-1 for i in range(n + 1)] -        self.size = [1 for i in range(n + 1)] +        class KeyDict(dict): +            # 辞書にないときの対応 +            def __missing__(self, key): +                self[key] = key +                return key -    # 検索 +        self.parent = KeyDict() +        self.rank = defaultdict(int) +        self.weight = defaultdict(lambda: 1) + +    # 根を探す -        path = [] -        curr = x -        # 親ノードの手前で止まる(どの根に紐づくかの情報を持ちながら) -        while self.par[curr] != -1: +        if self.parent[x] == x: +            return x +        else: +            # 経路圧縮 -            path.append(curr) -            curr = self.par[curr] -        for p in path: -            self.par[p] = curr -        return curr +            y = self.find(self.parent[x]) +            self.parent[x] = y  # 親の置き換え(圧縮) +            return self.parent[x] -        self.par[y] = x -        self.size[x] += self.size[y] -        self.size[y] = 1 +        # 低い方を高い方につなげる(親のランクによる) +        if self.rank[x] < self.rank[y]: +            self.parent[x] = y +            self.weight[y] += self.weight[x] +            self.weight[x] = 0 +        else: +            self.parent[y] = x +            self.weight[x] += self.weight[y] +            self.weight[y] = 0 +        if self.rank[x] == self.rank[y]: +            self.rank[x] += 1 -N, M = list(map(int, input().split())) -pairs = [tuple(map(int, input().split())) for _ in range(M)] -uf = UnionFind(N) -p = N * (N - 1) // 2 -ans = [p] -for a, b in reversed(pairs[1:]): +ps = [] +for i in range(m): +    a, b = list(map(int, input().split())) +    a -= 1 +    b -= 1 +    ps.append((a, b)) +uf = UnionFind(n) +now = n * (n - 1) // 2 +ans = [now] +for a, b in ps[::-1]: -        size_a = uf.size[uf.find(a)] -        size_b = uf.size[uf.find(b)] +        n1 = uf.weight[uf.find(a)] +        n2 = uf.weight[uf.find(b)] +        now += n1 * (n1 - 1) // 2 + n2 * (n2 - 1) // 2 - (n1 + n2) * (n1 + n2 - 1) // 2 -        size_a_update = uf.size[uf.find(a)] -        p = ( -            p -            + size_a * (size_a - 1) // 2 -            + size_b * (size_b - 1) // 2 -            - size_a_update * (size_a_update - 1) // 2 -        ) -    ans.append(p) -for a in reversed(ans): +    ans.append(now) +for a in ans[::-1][1:]: