human
Solve in Python:
There are N islands and M bridges.
The i-th bridge connects the A_i-th and B_i-th islands bidirectionally.
Initially, we can travel between any two islands using some of these bridges.
However, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to the M-th bridge.
Let the inconvenience be the number of pairs of islands (a, b) (a < b) such that we are no longer able to travel between the a-th and b-th islands using some of the bridges remaining.
For each i (1 \leq i \leq M), find the inconvenience just after the i-th bridge collapses.

-----Constraints-----
 - All values in input are integers.
 - 2 \leq N \leq 10^5
 - 1 \leq M \leq 10^5
 - 1 \leq A_i < B_i \leq N
 - All pairs (A_i, B_i) are distinct.
 - The inconvenience is initially 0.

-----Input-----
Input is given from Standard Input in the following format:
N M
A_1 B_1
A_2 B_2
\vdots
A_M B_M

-----Output-----
In the order i = 1, 2, ..., M, print the inconvenience just after the i-th bridge collapses.
Note that the answer may not fit into a 32-bit integer type.

-----Sample Input-----
4 5
1 2
3 4
1 3
2 3
1 4

-----Sample Output-----
0
0
4
5
6

For example, when the first to third bridges have collapsed, the inconvenience is 4 since we can no longer travel between the pairs (1, 2), (1, 3), (2, 4) and (3, 4).
 ... What is a Python code to find the inconvenience just after the i-th bridge collapses?
assistant
#Here is Python code to find the inconvenience just after the i-th bridge collapses.

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

def __starting_point():
    resolve()

__starting_point()