Buggy python submission (verdict: Runtime Error):
from collections import Counter, defaultdict, deque

class UnionFind(object):
    """Union find tree."""
    def __init__(self, nodes):
        self.par = list(range(nodes + 1))
        self.sizes = [1] * (nodes + 1)

    def root(self, key):
        if key != self.par[key]:
            self.par[key] = self.root(self.par[key])
        return self.par[key]

    def merge(self, a, b):
        ra = self.root(a)
        rb = self.root(b)
        if ra != rb:
            sa = self.sizes[ra]
            sb = self.sizes[rb]
            self.par[ra] = rb
            self.sizes[rb] += sa
            return sa * sb
        return 0

N, M = map(int, input().split())
AB = []
for _ in range(M):
    AB.append(list(map(int, input().split())))

uni = UnionFind(N)
comb = N * (N - 1) // 2
anses = [comb]
for a, b in AB[-1:0:-1]:
    red = uni.merge(a, b)
    comb -= red
    anses.append(comb)

for ans in reversed(anses):
    print(ans)

Fixed submission:
from collections import Counter, defaultdict, deque

class UnionFind(object):
    """Union find tree."""
    def __init__(self, nodes):
        self.par = list(range(nodes + 1))
        self.sizes = [1] * (nodes + 1)

    def root(self, key):
        if key != self.par[key]:
            k0 = key
            while k0 != self.par[k0]:
                k0 = self.par[k0]
            self.par[key] = k0
        return self.par[key]

    def merge(self, a, b):
        ra = self.root(a)
        rb = self.root(b)
        if ra != rb:
            sa = self.sizes[ra]
            sb = self.sizes[rb]
            self.par[ra] = rb
            self.sizes[rb] += sa
            return sa * sb
        return 0

N, M = map(int, input().split())
AB = []
for _ in range(M):
    AB.append(list(map(int, input().split())))

uni = UnionFind(N)
comb = N * (N - 1) // 2
anses = [comb]
for a, b in AB[-1:0:-1]:
    red = uni.merge(a, b)
    comb -= red
    anses.append(comb)

for ans in reversed(anses):
    print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import Counter, defaultdict, deque

class UnionFind(object):
    """Union find tree."""
    def __init__(self):
        self.par = {}
        self.sizes = {}

    def root(self, key):
        if key not in self.par:
            if key not in self.sizes:
                self.sizes[key] = 1
            return key
        self.par[key] = self.root(self.par[key])
        return self.par[key]

    def is_same(self, a, b):
        return self.root(a) == self.root(b)

    # return `now` connected nodes
    def merge(self, a, b):
        ra = self.root(a)
        rb = self.root(b)
        if ra != rb:
            sa = self.sizes[ra]
            sb = self.sizes[rb]
            self.par[ra] = rb
            self.sizes[rb] += sa
            return sa * sb
        return 0

N, M = map(int, input().split())
AB = []
for _ in range(M):
    AB.append(list(map(int, input().split())))

uni = UnionFind()
comb = N * (N - 1) // 2
anses = [comb]
for a, b in AB[-1:0:-1]:
    red = uni.merge(a, b)
    comb -= red
    anses.append(comb)

for ans in reversed(anses):
    print(ans)

Fixed submission:
from collections import Counter, defaultdict, deque

class UnionFind(object):
    """Union find tree."""
    def __init__(self, nodes):
        self.par = list(range(nodes + 1))
        self.sizes = [1] * (nodes + 1)

    def root(self, key):
        if key != self.par[key]:
            k0 = key
            while k0 != self.par[k0]:
                k0 = self.par[k0]
            self.par[key] = k0
        return self.par[key]

    def merge(self, a, b):
        ra = self.root(a)
        rb = self.root(b)
        if ra != rb:
            sa = self.sizes[ra]
            sb = self.sizes[rb]
            self.par[ra] = rb
            self.sizes[rb] += sa
            return sa * sb
        return 0

N, M = map(int, input().split())
AB = []
for _ in range(M):
    AB.append(list(map(int, input().split())))

uni = UnionFind(N)
comb = N * (N - 1) // 2
anses = [comb]
for a, b in AB[-1:0:-1]:
    red = uni.merge(a, b)
    comb -= red
    anses.append(comb)

for ans in reversed(anses):
    print(ans)