class UnionFind:
    __slots__ = ["_size", "_first_idx", "_parents"]

    def __init__(self, size: int, first_index: int = 0) -> None:
        self._size = size
        self._first_idx = first_index
        self._parents = [-1] * (size + first_index)

    def find(self, x: int) -> int:
        """Find the group (root) of vertex x"""
        if self._parents[x] < 0:
            return x
        self._parents[x] = self.find(self._parents[x])
        return self._parents[x]

    def is_same(self, x: int, y: int) -> bool:
        """Return whether two vertices x and y are in the same group or not."""
        return self.find(x) == self.find(y)

    def unite(self, x: int, y: int) -> None:
        """Unite two groups of vertices x and y."""
        x, y = self.find(x), 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 get_size(self, x: int) -> int:
        """Get the size of the group vertex x belongs"""
        return -self._parents[self.find(x)]

    @property
    def groups(self) -> int:
        """Return the number of groups."""
        return len({self.find(x) for x in range(self._first_idx, self._size + self._first_idx)})
n,m=map(int,input().split())
ab=[]
for _ in range(m):
    ab.append(list(map(int,input().split())))
ab = ab[::-1]
tree=UnionFind(n)
ans = (n*(n-1)//2)
res=[ans]
for a,b in ab[:-1]:
    a -=1
    b -=1
    if tree.is_same(a,b):
        pass
    else:
        ans -= tree.get_size(a)*tree.get_size(b)
    res.append(ans)
    tree.unite(a,b)
print(*[max(0,i) for i in res[::-1]], sep="\n") class UnionFind:
    __slots__ = ["_size", "_first_idx", "_parents"]

    def __init__(self, size: int, first_index: int = 0) -> None:
        self._size = size
        self._first_idx = first_index
        self._parents = [-1] * (size + first_index)

    def find(self, x: int) -> int:
        """Find the group (root) of vertex x"""
        if self._parents[x] < 0:
            return x
        self._parents[x] = self.find(self._parents[x])
        return self._parents[x]

    def is_same(self, x: int, y: int) -> bool:
        """Return whether two vertices x and y are in the same group or not."""
        return self.find(x) == self.find(y)

    def unite(self, x: int, y: int) -> None:
        """Unite two groups of vertices x and y."""
        x, y = self.find(x), 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 get_size(self, x: int) -> int:
        """Get the size of the group vertex x belongs"""
        return -self._parents[self.find(x)]

    @property
    def groups(self) -> int:
        """Return the number of groups."""
        return len({self.find(x) for x in range(self._first_idx, self._size + self._first_idx)}) UnionFind __slots__ = ["_size", "_first_idx", "_parents"] __slots__ ["_size", "_first_idx", "_parents"] "_size" "_first_idx" "_parents" def __init__(self, size: int, first_index: int = 0) -> None:
        self._size = size
        self._first_idx = first_index
        self._parents = [-1] * (size + first_index)

     __init__ self._size = size self._size self _size size self._first_idx = first_index self._first_idx self _first_idx first_index self._parents = [-1] * (size + first_index) self._parents self _parents [-1] * (size + first_index) [-1] -1 size + first_index size first_index self self size: int size first_index: int = 0 first_index 0 def find(self, x: int) -> int:
        """Find the group (root) of vertex x"""
        if self._parents[x] < 0:
            return x
        self._parents[x] = self.find(self._parents[x])
        return self._parents[x]

     find """Find the group (root) of vertex x""" if self._parents[x] < 0:
            return x
         self._parents[x] < 0 self._parents[x] self._parents self _parents x 0 return x x self._parents[x] = self.find(self._parents[x]) self._parents[x] self._parents self _parents x self.find(self._parents[x]) self.find self find self._parents[x] self._parents self _parents x return self._parents[x] self._parents[x] self._parents self _parents x self self x: int x def is_same(self, x: int, y: int) -> bool:
        """Return whether two vertices x and y are in the same group or not."""
        return self.find(x) == self.find(y)

     is_same """Return whether two vertices x and y are in the same group or not.""" 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: int x y: int y def unite(self, x: int, y: int) -> None:
        """Unite two groups of vertices x and y."""
        x, y = self.find(x), 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

     unite """Unite two groups of vertices x and y.""" x, y = self.find(x), self.find(y) x self.find(x) self.find self find x y self.find(y) self.find self find y if x == y:
            return

         x == y x y return if self._parents[x] > self._parents[y]:
            x, y = y, x
         self._parents[x] > self._parents[y] self._parents[x] self._parents self _parents x self._parents[y] self._parents self _parents y x, y = y, x x y y x self._parents[x] += self._parents[y] self._parents[x] self._parents self _parents x self._parents[y] self._parents self _parents y self._parents[y] = x self._parents[y] self._parents self _parents y x self self x: int x y: int y def get_size(self, x: int) -> int:
        """Get the size of the group vertex x belongs"""
        return -self._parents[self.find(x)]

     get_size """Get the size of the group vertex x belongs""" 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: int x def groups(self) -> int:
        """Return the number of groups."""
        return len({self.find(x) for x in range(self._first_idx, self._size + self._first_idx)}) groups """Return the number of groups.""" self.find(x) for x in range(self._first_idx, self._size + self._first_idx) for x in range(self._first_idx, self._size + self._first_idx) x range(self._first_idx, self._size + self._first_idx) range self._first_idx self _first_idx self._size + self._first_idx self._size self _size self._first_idx self _first_idx for x in range(self._first_idx, self._size + self._first_idx) self.find(x) self.find self find x return len({self.find(x) for x in range(self._first_idx, self._size + self._first_idx)}) len({self.find(x) for x in range(self._first_idx, self._size + self._first_idx)}) len self self @property
     groups property groups 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):
    ab.append(list(map(int,input().split()))) _ range(m) range m ab.append(list(map(int,input().split()))) ab.append ab append list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split ab = ab[::-1] ab ab[::-1] ab ::-1 -1 tree=UnionFind(n) tree UnionFind(n) UnionFind n ans = (n*(n-1)//2) ans n*(n-1)//2 n*(n-1) n n-1 n 1 2 res=[ans] res [ans] ans for a,b in ab[:-1]:
    a -=1
    b -=1
    if tree.is_same(a,b):
        pass
    else:
        ans -= tree.get_size(a)*tree.get_size(b)
    res.append(ans)
    tree.unite(a,b) a b ab[:-1] ab :-1 -1 a -=1 a 1 b -=1 b 1 if tree.is_same(a,b):
        pass
    else:
        ans -= tree.get_size(a)*tree.get_size(b)
     tree.is_same(a,b) tree.is_same tree is_same a b ans -= tree.get_size(a)*tree.get_size(b) ans tree.get_size(a)*tree.get_size(b) tree.get_size(a) tree.get_size tree get_size a tree.get_size(b) tree.get_size tree get_size b res.append(ans) res.append res append ans tree.unite(a,b) tree.unite tree unite a b max(0,i) for i in res[::-1] for i in res[::-1] i res[::-1] res ::-1 -1 for i in res[::-1] max(0,i) max 0 i print(*[max(0,i) for i in res[::-1]], sep="\n") print *[max(0,i) for i in res[::-1]] [max(0,i) for i in res[::-1]] sep="\n" sep "\n" ans -= tree.get_size(a)*tree.get_size(b) tree.get_size(a)*tree.get_size(b) ans ab = ab[::-1] ab[::-1] ab b -=1 1 b m=map(int,input().split()) map(int,input().split()) m class UnionFind:
    __slots__ = ["_size", "_first_idx", "_parents"]

    def __init__(self, size: int, first_index: int = 0) -> None:
        self._size = size
        self._first_idx = first_index
        self._parents = [-1] * (size + first_index)

    def find(self, x: int) -> int:
        """Find the group (root) of vertex x"""
        if self._parents[x] < 0:
            return x
        self._parents[x] = self.find(self._parents[x])
        return self._parents[x]

    def is_same(self, x: int, y: int) -> bool:
        """Return whether two vertices x and y are in the same group or not."""
        return self.find(x) == self.find(y)

    def unite(self, x: int, y: int) -> None:
        """Unite two groups of vertices x and y."""
        x, y = self.find(x), 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 get_size(self, x: int) -> int:
        """Get the size of the group vertex x belongs"""
        return -self._parents[self.find(x)]

    @property
    def groups(self) -> int:
        """Return the number of groups."""
        return len({self.find(x) for x in range(self._first_idx, self._size + self._first_idx)}) class UnionFind:
    __slots__ = ["_size", "_first_idx", "_parents"]

    def __init__(self, size: int, first_index: int = 0) -> None:
        self._size = size
        self._first_idx = first_index
        self._parents = [-1] * (size + first_index)

    def find(self, x: int) -> int:
        """Find the group (root) of vertex x"""
        if self._parents[x] < 0:
            return x
        self._parents[x] = self.find(self._parents[x])
        return self._parents[x]

    def is_same(self, x: int, y: int) -> bool:
        """Return whether two vertices x and y are in the same group or not."""
        return self.find(x) == self.find(y)

    def unite(self, x: int, y: int) -> None:
        """Unite two groups of vertices x and y."""
        x, y = self.find(x), 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 get_size(self, x: int) -> int:
        """Get the size of the group vertex x belongs"""
        return -self._parents[self.find(x)]

    @property
    def groups(self) -> int:
        """Return the number of groups."""
        return len({self.find(x) for x in range(self._first_idx, self._size + self._first_idx)}) UnionFind ab=[] [] ab ans = (n*(n-1)//2) n*(n-1)//2 ans a -=1 1 a res=[ans] [ans] res tree=UnionFind(n) UnionFind(n) tree n,m=map(int,input().split()) map(int,input().split()) n
class UnionFind:
    __slots__ = ["_size", "_first_idx", "_parents"]

    def __init__(self, size: int, first_index: int = 0) -> None:
        self._size = size
        self._first_idx = first_index
        self._parents = [-1] * (size + first_index)

    def find(self, x: int) -> int:
        """Find the group (root) of vertex x"""
        if self._parents[x] < 0:
            return x
        self._parents[x] = self.find(self._parents[x])
        return self._parents[x]

    def is_same(self, x: int, y: int) -> bool:
        """Return whether two vertices x and y are in the same group or not."""
        return self.find(x) == self.find(y)

    def unite(self, x: int, y: int) -> None:
        """Unite two groups of vertices x and y."""
        x, y = self.find(x), 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 get_size(self, x: int) -> int:
        """Get the size of the group vertex x belongs"""
        return -self._parents[self.find(x)]

    @property
    def groups(self) -> int:
        """Return the number of groups."""
        return len({self.find(x) for x in range(self._first_idx, self._size + self._first_idx)})
n,m=map(int,input().split())
ab=[]
for _ in range(m):
    ab.append(list(map(int,input().split())))
ab = ab[::-1]
tree=UnionFind(n)
ans = (n*(n-1)//2)
res=[ans]
for a,b in ab[:-1]:
    a -=1
    b -=1
    if tree.is_same(a,b):
        pass
    else:
        ans -= tree.get_size(a)*tree.get_size(b)
    res.append(ans)
    tree.unite(a,b)
print(*[max(0,i) for i in res[::-1]], sep="\n")