import sys



sys.setrecursionlimit(10 ** 7)

input = sys.stdin.readline

f_inf = float('inf')

mod = 10 ** 9 + 7



\



class UnionFind:

    def __init__(self, n):

        self.n = n

        self.parents = [-1] * n



    # 親が同じか判別

    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 same(self, x, y):

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



    # 連結成分の大きさを返す

    def size(self, x):

        return -self.parents[self.find(x)]





def resolve():

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

    AB = [list(map(int, input().split())) for _ in range(m)][::-1]

    uf = UnionFind(n)



    res = [(n * (n - 1)) // 2]

    for a, b in AB:

        if not uf.same(a - 1, b - 1):

            pre1 = uf.size(a - 1)

            pre2 = uf.size(b - 1)

            pre_score = (pre1 * (pre1 - 1)) // 2 + (pre2 * (pre2 - 1)) // 2



            uf.union(a - 1, b - 1)

            now = uf.size(a - 1)

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



            res.append(res[-1] + pre_score - now_score)

        else:

            res.append(res[-1])



    for i in reversed(list(range(m))):

        print((res[i]))





if __name__ == '__main__':

    resolve()

import sys



sys.setrecursionlimit(10 ** 7)

f_inf = float('inf')

mod = 10 ** 9 + 7





class UnionFind:

    def __init__(self, n):

        self.n = n

        self.parents = [-1] * n



    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):

        """

        yをxの根に繋ぐ

        """

        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 same(self, x, y):

        """

        xとyが同じ連結成分か判別する

        """

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



    def size(self, x):

        """

        xの連結成分の大きさを返す

        """

        return -self.parents[self.find(x)]



    def kruskal(self, edge):

        """

        :param edge: edge = [(コスト, 頂点1, 頂点2),...]の形で重み付き隣接リストを渡して下さい

        :return: 最小全域木のコストの和

        """

        edge.sort()

        cost_sum = 0

        for cost, node1, node2 in edge:

            if not self.same(node1, node2):

                cost_sum += cost

                self.union(node1, node2)

        return cost_sum





def resolve():

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

    edge = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(m)]

    uf = UnionFind(n)

    res = [(n - 1) * n // 2]

    for i in reversed(range(1, m)):

        a, b = edge[i]

        if not uf.same(a, b):

            res.append(res[-1] - uf.size(a) * uf.size(b))

            uf.union(a, b)

        else:

            res.append(res[-1])

    print(*res[::-1], sep="\n")





if __name__ == '__main__':

    resolve()

import sys

sys.setrecursionlimit(10**7)
input = sys.stdin.readline
f_inf = float("inf")
mod = 10**9 + 7


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    # 親が同じか判別
    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 same(self, x, y):
        return self.find(x) == self.find(y)

    # 連結成分の大きさを返す
    def size(self, x):
        return -self.parents[self.find(x)]


def resolve():
    n, m = list(map(int, input().split()))
    AB = [list(map(int, input().split())) for _ in range(m)][::-1]
    uf = UnionFind(n)
    res = [(n * (n - 1)) // 2]
    for a, b in AB:
        if not uf.same(a - 1, b - 1):
            pre1 = uf.size(a - 1)
            pre2 = uf.size(b - 1)
            pre_score = (pre1 * (pre1 - 1)) // 2 + (pre2 * (pre2 - 1)) // 2
            uf.union(a - 1, b - 1)
            now = uf.size(a - 1)
            now_score = (now * (now - 1)) // 2
            res.append(res[-1] + pre_score - now_score)
        else:
            res.append(res[-1])
    for i in reversed(list(range(m))):
        print((res[i]))


if __name__ == "__main__":
    resolve()

import sys

sys.setrecursionlimit(10**7)
f_inf = float("inf")
mod = 10**9 + 7


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    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):
        """
        yをxの根に繋ぐ
        """
        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 same(self, x, y):
        """
        xとyが同じ連結成分か判別する
        """
        return self.find(x) == self.find(y)

    def size(self, x):
        """
        xの連結成分の大きさを返す
        """
        return -self.parents[self.find(x)]

    def kruskal(self, edge):
        """
        :param edge: edge = [(コスト, 頂点1, 頂点2),...]の形で重み付き隣接リストを渡して下さい
        :return: 最小全域木のコストの和
        """
        edge.sort()
        cost_sum = 0
        for cost, node1, node2 in edge:
            if not self.same(node1, node2):
                cost_sum += cost
                self.union(node1, node2)
        return cost_sum


def resolve():
    n, m = map(int, input().split())
    edge = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(m)]
    uf = UnionFind(n)
    res = [(n - 1) * n // 2]
    for i in reversed(range(1, m)):
        a, b = edge[i]
        if not uf.same(a, b):
            res.append(res[-1] - uf.size(a) * uf.size(b))
            uf.union(a, b)
        else:
            res.append(res[-1])
    print(*res[::-1], sep="\n")


if __name__ == "__main__":
    resolve()

-input = sys.stdin.readline -    # 親が同じか判別 +        """ +        親が同じか判別する +        """ -    # 根を繋ぎ直す +        """ +        yをxの根に繋ぐ +        """ -    # 親が同じか判別 +        """ +        xとyが同じ連結成分か判別する +        """ -    # 連結成分の大きさを返す +        """ +        xの連結成分の大きさを返す +        """ + +    def kruskal(self, edge): +        """ +        :param edge: edge = [(コスト, 頂点1, 頂点2),...]の形で重み付き隣接リストを渡して下さい +        :return: 最小全域木のコストの和 +        """ +        edge.sort() +        cost_sum = 0 +        for cost, node1, node2 in edge: +            if not self.same(node1, node2): +                cost_sum += cost +                self.union(node1, node2) +        return cost_sum -    n, m = list(map(int, input().split())) -    AB = [list(map(int, input().split())) for _ in range(m)][::-1] +    n, m = map(int, input().split()) +    edge = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(m)] -    res = [(n * (n - 1)) // 2] -    for a, b in AB: -        if not uf.same(a - 1, b - 1): -            pre1 = uf.size(a - 1) -            pre2 = uf.size(b - 1) -            pre_score = (pre1 * (pre1 - 1)) // 2 + (pre2 * (pre2 - 1)) // 2 -            uf.union(a - 1, b - 1) -            now = uf.size(a - 1) -            now_score = (now * (now - 1)) // 2 -            res.append(res[-1] + pre_score - now_score) +    res = [(n - 1) * n // 2] +    for i in reversed(range(1, m)): +        a, b = edge[i] +        if not uf.same(a, b): +            res.append(res[-1] - uf.size(a) * uf.size(b)) +            uf.union(a, b) -    for i in reversed(list(range(m))): -        print((res[i])) +    print(*res[::-1], sep="\n")