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

    def find(self, x):
        p = self.__parents
        if p[x] < 0:
            return x
        parent = self.find(p[x])
        p[x] = parent
        return parent

    def union(self, x, y):
        p = self.__parents
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if p[x] > p[y]:
            x, y = y, x
        p[x] += p[y]
        p[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 spline(func_=int, iter_=None):
    if iter_ is None:
        iter_ = input().split()
    return map(func_, iter_)


def main():
    n, m = spline()
    chains = UnionFindTree(n)
    f = lambda x: int(x) - 1
    bridges = [tuple(spline(func_=f)) for _ in range(m)]
    ans = [0] * m
    ans[-1] = n * (n - 1) // 2
    for i in range(m - 2, -1, -1):
        x, y = bridges.pop()
        tmp = ans[i + 1]
        if not chains.same(x, y):
            tmp -= chains.size(x) * chains.size(y)
            chains.union(x, y)
        ans[i] = tmp
    print(*ans, sep='\n')


if __name__ == "__main__":
    main() class UnionFindTree:
    def __init__(self, n):
        self.__parents = [-1] * n

    def find(self, x):
        p = self.__parents
        if p[x] < 0:
            return x
        parent = self.find(p[x])
        p[x] = parent
        return parent

    def union(self, x, y):
        p = self.__parents
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if p[x] > p[y]:
            x, y = y, x
        p[x] += p[y]
        p[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.__parents[self.find(x)] UnionFindTree def __init__(self, n):
        self.__parents = [-1] * n

     __init__ self.__parents = [-1] * n self.__parents self __parents [-1] * n [-1] -1 n self self n n def find(self, x):
        p = self.__parents
        if p[x] < 0:
            return x
        parent = self.find(p[x])
        p[x] = parent
        return parent

     find p = self.__parents p self.__parents self __parents if p[x] < 0:
            return x
         p[x] < 0 p[x] p x 0 return x x parent = self.find(p[x]) parent self.find(p[x]) self.find self find p[x] p x p[x] = parent p[x] p x parent return parent parent self self x x def union(self, x, y):
        p = self.__parents
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if p[x] > p[y]:
            x, y = y, x
        p[x] += p[y]
        p[y] = x

     union p = self.__parents p self.__parents self __parents 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 False
         x == y x y return False False if p[x] > p[y]:
            x, y = y, x
         p[x] > p[y] p[x] p x p[y] p y x, y = y, x x y y x p[x] += p[y] p[x] p x p[y] p y p[y] = x p[y] p y x 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 size(self, x):
        return -self.__parents[self.find(x)] size return -self.__parents[self.find(x)] -self.__parents[self.find(x)] self.__parents[self.find(x)] self.__parents self __parents self.find(x) self.find self find x self self x x def spline(func_=int, iter_=None):
    if iter_ is None:
        iter_ = input().split()
    return map(func_, iter_) spline if iter_ is None:
        iter_ = input().split()
     iter_ is None iter_ None iter_ = input().split() iter_ input().split() ().split () input split return map(func_, iter_) map(func_, iter_) map func_ iter_ func_=int func_ int iter_=None iter_ None def main():
    n, m = spline()
    chains = UnionFindTree(n)
    f = lambda x: int(x) - 1
    bridges = [tuple(spline(func_=f)) for _ in range(m)]
    ans = [0] * m
    ans[-1] = n * (n - 1) // 2
    for i in range(m - 2, -1, -1):
        x, y = bridges.pop()
        tmp = ans[i + 1]
        if not chains.same(x, y):
            tmp -= chains.size(x) * chains.size(y)
            chains.union(x, y)
        ans[i] = tmp
    print(*ans, sep='\n') main n, m = spline() n spline() spline m chains = UnionFindTree(n) chains UnionFindTree(n) UnionFindTree n f = lambda x: int(x) - 1 f lambda x: int(x) - 1 int(x) - 1 int(x) int x 1 x tuple(spline(func_=f)) for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) tuple(spline(func_=f)) tuple spline(func_=f) spline func_=f func_ f bridges = [tuple(spline(func_=f)) for _ in range(m)] bridges [tuple(spline(func_=f)) for _ in range(m)] ans = [0] * m ans [0] * m [0] 0 m ans[-1] = n * (n - 1) // 2 ans[-1] ans -1 n * (n - 1) // 2 n * (n - 1) n n - 1 n 1 2 for i in range(m - 2, -1, -1):
        x, y = bridges.pop()
        tmp = ans[i + 1]
        if not chains.same(x, y):
            tmp -= chains.size(x) * chains.size(y)
            chains.union(x, y)
        ans[i] = tmp
     i range(m - 2, -1, -1) range m - 2 m 2 -1 -1 x, y = bridges.pop() x bridges.pop() bridges.pop bridges pop y tmp = ans[i + 1] tmp ans[i + 1] ans i + 1 i 1 if not chains.same(x, y):
            tmp -= chains.size(x) * chains.size(y)
            chains.union(x, y)
         not chains.same(x, y) chains.same(x, y) chains.same chains same x y tmp -= chains.size(x) * chains.size(y) tmp chains.size(x) * chains.size(y) chains.size(x) chains.size chains size x chains.size(y) chains.size chains size y chains.union(x, y) chains.union chains union x y ans[i] = tmp ans[i] ans i tmp print(*ans, sep='\n') print *ans ans sep='\n' sep '\n' if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def spline(func_=int, iter_=None):
    if iter_ is None:
        iter_ = input().split()
    return map(func_, iter_) def spline(func_=int, iter_=None):
    if iter_ is None:
        iter_ = input().split()
    return map(func_, iter_) spline class UnionFindTree:
    def __init__(self, n):
        self.__parents = [-1] * n

    def find(self, x):
        p = self.__parents
        if p[x] < 0:
            return x
        parent = self.find(p[x])
        p[x] = parent
        return parent

    def union(self, x, y):
        p = self.__parents
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if p[x] > p[y]:
            x, y = y, x
        p[x] += p[y]
        p[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.__parents[self.find(x)] class UnionFindTree:
    def __init__(self, n):
        self.__parents = [-1] * n

    def find(self, x):
        p = self.__parents
        if p[x] < 0:
            return x
        parent = self.find(p[x])
        p[x] = parent
        return parent

    def union(self, x, y):
        p = self.__parents
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if p[x] > p[y]:
            x, y = y, x
        p[x] += p[y]
        p[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.__parents[self.find(x)] UnionFindTree def main():
    n, m = spline()
    chains = UnionFindTree(n)
    f = lambda x: int(x) - 1
    bridges = [tuple(spline(func_=f)) for _ in range(m)]
    ans = [0] * m
    ans[-1] = n * (n - 1) // 2
    for i in range(m - 2, -1, -1):
        x, y = bridges.pop()
        tmp = ans[i + 1]
        if not chains.same(x, y):
            tmp -= chains.size(x) * chains.size(y)
            chains.union(x, y)
        ans[i] = tmp
    print(*ans, sep='\n') def main():
    n, m = spline()
    chains = UnionFindTree(n)
    f = lambda x: int(x) - 1
    bridges = [tuple(spline(func_=f)) for _ in range(m)]
    ans = [0] * m
    ans[-1] = n * (n - 1) // 2
    for i in range(m - 2, -1, -1):
        x, y = bridges.pop()
        tmp = ans[i + 1]
        if not chains.same(x, y):
            tmp -= chains.size(x) * chains.size(y)
            chains.union(x, y)
        ans[i] = tmp
    print(*ans, sep='\n') main
class UnionFindTree:
    def __init__(self, n):
        self.__parents = [-1] * n

    def find(self, x):
        p = self.__parents
        if p[x] < 0:
            return x
        parent = self.find(p[x])
        p[x] = parent
        return parent

    def union(self, x, y):
        p = self.__parents
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if p[x] > p[y]:
            x, y = y, x
        p[x] += p[y]
        p[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 spline(func_=int, iter_=None):
    if iter_ is None:
        iter_ = input().split()
    return map(func_, iter_)


def main():
    n, m = spline()
    chains = UnionFindTree(n)
    f = lambda x: int(x) - 1
    bridges = [tuple(spline(func_=f)) for _ in range(m)]
    ans = [0] * m
    ans[-1] = n * (n - 1) // 2
    for i in range(m - 2, -1, -1):
        x, y = bridges.pop()
        tmp = ans[i + 1]
        if not chains.same(x, y):
            tmp -= chains.size(x) * chains.size(y)
            chains.union(x, y)
        ans[i] = tmp
    print(*ans, sep='\n')


if __name__ == "__main__":
    main()
