Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
ils = [map(int, input().split()) for _ in range(M)]

par = [i for i in range(0, N + 1)]
size = [1] * (N + 1)

def root(x):
    if par[x] == x:
        return x
    else:
        par[x] = root(par[x])
        return par[x]
        
def unite(x, y):
    x = root(x)
    y = root(y)
    if x == y:
      return
    par[x] = y
    size[y] += size[x]
    size[x] = size[y]
    
def same(x, y):
    return root(x) == root(y)
    
    
inconv = N * (N - 1) // 2
inconvs = [inconv]
for A, B in ils[M + 1:0:-1]:
    if not same(A, B):
        inconv -= size[root(A)] * size[root(B)]
        unite(A, B)
    inconvs.insert(0, inconv)
    
for i in inconvs:
    print(i)

Fixed submission:
N, M = map(int, input().split())
ils = [map(int, input().split()) for _ in range(M)]

par = [-1 for i in range(N)]

def root(x):
    if par[x] < 0:
        return x
    else:
        par[x] = root(par[x])
        return par[x]
        
def unite(x, y):
    x = root(x)
    y = root(y)
    if x == y:
        return
    if size(x) < size(y):
        x, y = y, x
    par[x] += par[y]
    par[y] = x
    
def same(x, y):
    return root(x) == root(y)

def size(x):
    return - par[root(x)]
    
    
inconv = N * (N - 1) // 2
result = [0] * M
for i in range(M - 1, -1, -1):
    A, B = ils[i]
    A -= 1
    B -= 1
    result[i] = inconv
    if not same(A, B):
        inconv -= size(A) * size(B)
        unite(A, B)
    
for i in result:
    print(i)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
ils = [map(int, input().split()) for _ in range(M)]

par = [i for i in range(0, N + 1)]
size = [1] * (N + 1)

def root(x):
    if par[x] == x:
        return x
    else:
        par[x] = root(par[x])
        return par[x]
        
def unite(x, y):
    x = root(x)
    y = root(y)
    if x == y:
      return
    par[x] = y
    size[y] += size[x]
    size[x] = size[y]
    
    
inconv = N * (N - 1) // 2
inconvs = [inconv]
for A, B in ils[M + 1:0:-1]:
    inconv -= size[root(A)] * size[root(B)]
    inconv = max(0, inconv)
    unite(A, B)
    inconvs.insert(0, inconv)
    
print('\n'.join(map(str, inconvs)))

Fixed submission:
N, M = map(int, input().split())
ils = [map(int, input().split()) for _ in range(M)]

par = [-1 for i in range(N)]

def root(x):
    if par[x] < 0:
        return x
    else:
        par[x] = root(par[x])
        return par[x]
        
def unite(x, y):
    x = root(x)
    y = root(y)
    if x == y:
        return
    if size(x) < size(y):
        x, y = y, x
    par[x] += par[y]
    par[y] = x
    
def same(x, y):
    return root(x) == root(y)

def size(x):
    return - par[root(x)]
    
    
inconv = N * (N - 1) // 2
result = [0] * M
for i in range(M - 1, -1, -1):
    A, B = ils[i]
    A -= 1
    B -= 1
    result[i] = inconv
    if not same(A, B):
        inconv -= size(A) * size(B)
        unite(A, B)
    
for i in result:
    print(i)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
ils = [map(int, input().split()) for _ in range(M)]

par = [i for i in range(N)]
size = [1] * N

def root(x):
    if par[x] == x:
        return x
    else:
        par[x] = root(par[x])
        
def unit(x, y):
    x = root(x)
    y = root(y)
    if x == y:
      return
    par[x] = y
    size[y] += size[x]
    size[x] = size[y]
    
    
inconv = N * (N - 1) // 2
inconvs = [inconv]
for A, B in ils[::-1]
    inconv -= size(root(A)) * size(root(B))
    unite(A, B)
    inconvs.insert(0, inconv)
    
print('\n'.join(inconvs))
  
    

Fixed submission:
N, M = map(int, input().split())
ils = [map(int, input().split()) for _ in range(M)]

par = [-1 for i in range(N)]

def root(x):
    if par[x] < 0:
        return x
    else:
        par[x] = root(par[x])
        return par[x]
        
def unite(x, y):
    x = root(x)
    y = root(y)
    if x == y:
        return
    if size(x) < size(y):
        x, y = y, x
    par[x] += par[y]
    par[y] = x
    
def same(x, y):
    return root(x) == root(y)

def size(x):
    return - par[root(x)]
    
    
inconv = N * (N - 1) // 2
result = [0] * M
for i in range(M - 1, -1, -1):
    A, B = ils[i]
    A -= 1
    B -= 1
    result[i] = inconv
    if not same(A, B):
        inconv -= size(A) * size(B)
        unite(A, B)
    
for i in result:
    print(i)