Buggy python submission (verdict: Runtime Error):
import sys
n , m, *e = map(int,sys.stdin.read().split())
total = n*(n-1)//2
ans =[total]
u = [-1]*(n+1)

def find(x):
    if u[x] < 0 :
        return x
    else:
        return find(u[x])

for x , y in zip(e[-2:1:-2],e[:1:-2]):
    x = find(x)
    y = find(y)
    if x != y:
        total -= u[x] * u[y]
        u[x] += u[y]
        u[y] = x
    ans += [total]

print(*ans[::-1], sep="\n")

Fixed submission:
import sys
n , m, *e = map(int,sys.stdin.read().split())
total = n*(n-1)//2
ans =[total]
u = [-1]*(n+1)

def find(x):
    if u[x] < 0 :
        return x
    else:
        return find(u[x])

for x , y in zip(e[-2:1:-2],e[:1:-2]):
    x = find(x)
    y = find(y)
    x, y = sorted((x, y))
    if x != y:
        total -= u[x] * u[y]
        u[x] += u[y]
        u[y] = x
    ans += [total]

print(*ans[::-1], sep="\n")

Buggy python submission (verdict: Runtime Error):
import sys
n , m, *e = map(int,sys.stdin.read().split())
total = n*(n-1)//2
ans =[total]
u = [-1]*(n+1)

def find(x):
    if u[x] < 0 :
        return x
    else:
        return find(u[x])

for x , y in zip(e[-2:1:-2],e[:1:-2]):
    x = find(x)
    y = find(y)
    if x != y:
        total -= u[x] * u[y]
        u[x] += u[y]
        u[y] = x　　
    ans += [total]
    print(u)

print(*ans[::-1], sep="\n")

Fixed submission:
import sys
n , m, *e = map(int,sys.stdin.read().split())
total = n*(n-1)//2
ans =[total]
u = [-1]*(n+1)

def find(x):
    if u[x] < 0 :
        return x
    else:
        return find(u[x])

for x , y in zip(e[-2:1:-2],e[:1:-2]):
    x = find(x)
    y = find(y)
    x, y = sorted((x, y))
    if x != y:
        total -= u[x] * u[y]
        u[x] += u[y]
        u[y] = x
    ans += [total]

print(*ans[::-1], sep="\n")

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(2000)
n, m = map(int, input().split())
bridge = list(map(int, sys.stdin.read().split()))
total = n*(n-1)//2
ans =[total]
u = [-1]*(n+1)
size = [1]*(n+1)
rank = [1]*(n+1)
def check(x, y):
    return find(x) != find(y)

def find(x):
    if u[x] < 0 :
        u[x] = x
        return x
    else:
        return u[x]

for x , y in zip(bridge[-2::-2],bridge[::-2]):
    if check(x, y):
        X = find(x)
        Y = find(y)
        total -= size[X] * size[Y]
        ans += [total]
        if rank[X] == rank[Y]:
            u = [Y if x == X else x for x in u]
            rank =[x+1 if u[i] == Y else x for i, x in enumerate(rank)]
        else:
            if rank[X] > rank[Y]:
                X, Y = Y, X
            rank =[x+1 if u[i] == X else x for i, x in enumerate(rank)]
            u = [Y if x == X else x for x in u]
        size[Y] += size[X]

    else:
        ans += [total]

print(*ans[-2::-1], sep="\n")

Fixed submission:
import sys
n , m, *e = map(int,sys.stdin.read().split())
total = n*(n-1)//2
ans =[total]
u = [-1]*(n+1)

def find(x):
    if u[x] < 0 :
        return x
    else:
        return find(u[x])

for x , y in zip(e[-2:1:-2],e[:1:-2]):
    x = find(x)
    y = find(y)
    x, y = sorted((x, y))
    if x != y:
        total -= u[x] * u[y]
        u[x] += u[y]
        u[y] = x
    ans += [total]

print(*ans[::-1], sep="\n")

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(2000)
n, m = map(int, input().split())
bridge = list(map(int, sys.stdin.read().split()))
total = n*(n-1)//2
ans =[total]
u = [i for i in range(n+1)]
size = [1 for i in range(n+1)]
rank = [1 for i in range(n+1)]
def check(x, y):
    return find(x) != find(y)

def find(x):
    if x == u[x]:
        return x
    else:
        return u[x]

for x , y in zip(bridge[-2::-2],bridge[::-2]):
    if check(x, y):
        X = u[x]
        Y = u[y]
        total -= size[X] * size[Y]
        ans += [total]

        if rank[X] == rank[Y]:
            u = [Y if i == X else i for i in u]
            rank =[x+1 if u[i] == u[Y] else x for i, x in enumerate(rank)]
        else:
            if rank[X] > rank[Y]:
                X, Y = Y, X
            rank =[x+1 if u[i] == u[Y] else x for i, x in enumerate(rank)]
            u = [Y if i == u[X] else i for i in u]
        size[Y] += size[X]

    else:
        ans += [total]

print(*ans[-2::-1], sep="\n")


Fixed submission:
import sys
n , m, *e = map(int,sys.stdin.read().split())
total = n*(n-1)//2
ans =[total]
u = [-1]*(n+1)

def find(x):
    if u[x] < 0 :
        return x
    else:
        return find(u[x])

for x , y in zip(e[-2:1:-2],e[:1:-2]):
    x = find(x)
    y = find(y)
    x, y = sorted((x, y))
    if x != y:
        total -= u[x] * u[y]
        u[x] += u[y]
        u[y] = x
    ans += [total]

print(*ans[::-1], sep="\n")

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(2000)
n, m = map(int, input().split())
bridge = list(map(int, sys.stdin.read().split()))
total = n*(n-1)//2
ans =[total]
u = [i for i in range(n+1)]
size = [1 for i in range(n+1)]
rank = [1 for i in range(n+1)]
def check(x, y):
    return find(x) != find(y)

def find(x):
    if x == u[x]:
        return x
    else:
        return u[x]

for x , y in zip(bridge[-2::-2],bridge[::-2]):
    if check(x, y):
        X = u[x]
        Y = u[y]
        total -= size[X] * size[Y]
        ans += [total]
        if rank[X] == rank[Y]:
            X, Y = sorted([X,Y])
            u = [Y if i == X else i for i in u]
            rank =[x+1 if u[i] == u[Y] else x for i, x in enumerate(rank)]
        else:
            if rank[X] > rank[Y]:
                X, Y = sorted([X,Y])
            rank =[x+1 if u[i] == u[Y] else x for i, x in enumerate(rank)]
            u = [Y if i == u[X] else i for i in u]
        size[Y] += size[X]

    else:
        ans += [total]

print(*ans[-2::-1], sep="\n")

Fixed submission:
import sys
n , m, *e = map(int,sys.stdin.read().split())
total = n*(n-1)//2
ans =[total]
u = [-1]*(n+1)

def find(x):
    if u[x] < 0 :
        return x
    else:
        return find(u[x])

for x , y in zip(e[-2:1:-2],e[:1:-2]):
    x = find(x)
    y = find(y)
    x, y = sorted((x, y))
    if x != y:
        total -= u[x] * u[y]
        u[x] += u[y]
        u[y] = x
    ans += [total]

print(*ans[::-1], sep="\n")

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(2000)
n, m = map(int, input().split())
bridge = list(map(int, sys.stdin.read().split()))
total = n*(n-1)//2
ans =[total]
u = [i for i in range(n+1)]
size = [1 for i in range(n+1)]
rank = [1 for i in range(n+1)]
def check(x, y):
    return find(x) != find(y)

def find(x):
    if x == u[x]:
        return x
    else:
        return u[x]

for x , y in zip(bridge[-2::-2],bridge[::-2]):
    if check(x, y):
        X = find(x)
        Y = find(y)
        total -= size[X] * size[Y]
        ans += [total]
        if rank[X] == rank[Y]:
            X, Y = sorted([X,Y])
            u = [Y if i == X else i for i in u]
            rank =[x+1 if u[i] == u[Y] else x for i, x in enumerate(rank)]
        else:
            if rank[X] > rank[Y]:
                X, Y = sorted([X,Y])
            rank =[x+1 if u[i] == u[Y] else x for i, x in enumerate(rank)]
            u = [Y if i == u[X] else i for i in u]
        size[Y] += size[X]

    else:
        ans += [total]

print(*ans[-2::-1], sep="\n")

Fixed submission:
import sys
n , m, *e = map(int,sys.stdin.read().split())
total = n*(n-1)//2
ans =[total]
u = [-1]*(n+1)

def find(x):
    if u[x] < 0 :
        return x
    else:
        return find(u[x])

for x , y in zip(e[-2:1:-2],e[:1:-2]):
    x = find(x)
    y = find(y)
    x, y = sorted((x, y))
    if x != y:
        total -= u[x] * u[y]
        u[x] += u[y]
        u[y] = x
    ans += [total]

print(*ans[::-1], sep="\n")

Buggy python submission (verdict: Time Limit Exceeded):
import sys

n, m = map(int, input().split())
bridge = list(map(int, sys.stdin.read().split()))
total = n*(n-1)//2
ans =[total]
u = [i for i in range(n+1)]
size = [1 for i in range(n+1)]
rank = [1 for i in range(n+1)]
def check(x, y):
    return find(x) != find(y)

def find(x):
    if x == u[x]:
        return x
    else:
        u[x] = find(u[x])
        return u[x]

for x , y in zip(bridge[-2::-2],bridge[::-2]):
    if check(x, y):
        X = find(x)
        Y = find(y)
        total -= size[X] * size[Y]
        ans += [total]
        if rank[X] == rank[Y]:
            X, Y = sorted([X,Y])
            u = [Y if i == X else i for i in u]
            rank =[x+1 if u[i] == u[Y] else x for i, x in enumerate(rank)]
        else:
            if rank[X] > rank[Y]:
                X, Y = sorted([X,Y])
            rank =[x+1 if u[i] == u[Y] else x for i, x in enumerate(rank)]
            u = [Y if i == u[X] else i for i in u]
        size[Y] += size[X]

    else:
        ans += [total]

print(*ans[-2::-1], sep="\n")


Fixed submission:
import sys
n , m, *e = map(int,sys.stdin.read().split())
total = n*(n-1)//2
ans =[total]
u = [-1]*(n+1)

def find(x):
    if u[x] < 0 :
        return x
    else:
        return find(u[x])

for x , y in zip(e[-2:1:-2],e[:1:-2]):
    x = find(x)
    y = find(y)
    x, y = sorted((x, y))
    if x != y:
        total -= u[x] * u[y]
        u[x] += u[y]
        u[y] = x
    ans += [total]

print(*ans[::-1], sep="\n")

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10000)
n, m = map(int, input().split())
bridge = list(map(int, sys.stdin.read().split()))
total = n*(n-1)//2
ans =[total]
u = [i for i in range(n+1)]
size = [1 for i in range(n+1)]
def unite(x, y):
    return find(x) != find(y)

def find(x):
    if x == u[x]:
        return x
    else:
        u[x] = find(u[x])
        return u[x]

for x , y in zip(bridge[-2::-2],bridge[::-2]):
    if unite(x, y):
        X = find(x)
        Y = find(y)
        total -= size[X] * size[Y]
        ans += [total]
        if size[X] >= size[Y]:
            X, Y = sorted([X,Y])
        u = [Y if i == X else i for i in u]
        size[Y] += size[X]
        size[X] = 0

    else:
        ans += [total]

print(*ans[-2::-1], sep="\n")

Fixed submission:
import sys
n , m, *e = map(int,sys.stdin.read().split())
total = n*(n-1)//2
ans =[total]
u = [-1]*(n+1)

def find(x):
    if u[x] < 0 :
        return x
    else:
        return find(u[x])

for x , y in zip(e[-2:1:-2],e[:1:-2]):
    x = find(x)
    y = find(y)
    x, y = sorted((x, y))
    if x != y:
        total -= u[x] * u[y]
        u[x] += u[y]
        u[y] = x
    ans += [total]

print(*ans[::-1], sep="\n")

Buggy python submission (verdict: Time Limit Exceeded):
import sys
n, m = map(int, input().split())
bridge = list(map(int, sys.stdin.read().split()))
total = n*(n-1)//2
ans =[total]
u = [i for i in range(n+1)]
size = [1 for i in range(n+1)]
def unite(x, y):
    if find(x) != find(y):
        return 1
    else:
        return 0

def find(x):
    if x == u[x]:
        return x
    else:
        u[x] = find(u[x])
        return u[x]

for x , y in zip(bridge[-2::-2],bridge[::-2]):
    if unite(x, y):
        X = find(x)
        Y = find(y)
        total -= size[X] * size[Y]
        ans += [total]
        if size[X] >= size[Y]:
            X, Y = sorted([X,Y])
        u = [Y if i == X else i for i in u]
        size[Y] += size[X]
        size[X] = 0

    else:
        ans += [total]

print(*ans[-2::-1], sep="\n")

Fixed submission:
import sys
n , m, *e = map(int,sys.stdin.read().split())
total = n*(n-1)//2
ans =[total]
u = [-1]*(n+1)

def find(x):
    if u[x] < 0 :
        return x
    else:
        return find(u[x])

for x , y in zip(e[-2:1:-2],e[:1:-2]):
    x = find(x)
    y = find(y)
    x, y = sorted((x, y))
    if x != y:
        total -= u[x] * u[y]
        u[x] += u[y]
        u[y] = x
    ans += [total]

print(*ans[::-1], sep="\n")

Buggy python submission (verdict: Time Limit Exceeded):
import sys
n, m = map(int, input().split())
bridge = list(map(int, sys.stdin.read().split()))
total = n*(n-1)//2
ans =[total]
u = [i for i in range(n+1)]
size = [1 for i in range(n+1)]
def unite(x, y):
    if find(x) != find(y):
        return 1
    else:
        return 0

def find(x):
    if x != u[x]:
        x =u[x]
        find(x)
    return x

for x , y in zip(bridge[-2::-2],bridge[::-2]):
    if unite(x, y):
        X = find(x)
        Y = find(y)
        total -= size[X] * size[Y]
        ans += [total]
        if size[X] >= size[Y]:
            X, Y = sorted([X,Y])
        u = [Y if i == X else i for i in u]
        size[Y] += size[X]
        size[X] = 0

    else:
        ans += [total]

print(*ans[-2::-1], sep="\n")

Fixed submission:
import sys
n , m, *e = map(int,sys.stdin.read().split())
total = n*(n-1)//2
ans =[total]
u = [-1]*(n+1)

def find(x):
    if u[x] < 0 :
        return x
    else:
        return find(u[x])

for x , y in zip(e[-2:1:-2],e[:1:-2]):
    x = find(x)
    y = find(y)
    x, y = sorted((x, y))
    if x != y:
        total -= u[x] * u[y]
        u[x] += u[y]
        u[y] = x
    ans += [total]

print(*ans[::-1], sep="\n")

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n, m = map(int, input().split())
bridge = []
for i in range(m):
    bridge += list(map(int, input().split()))
bridge = np.array(bridge).reshape(m, 2)
total = n*(n-1)//2
ans =[total]
u = [i for i in range(n+1)]
size = [1 for i in range(n+1)]
def unite(x, y):
    if find(x) != find(y):
        return 1
    else:
        return 0

def find(x):
    if x != u[x]:
        x =u[x]
        find(x)
    return x

for x , y in bridge[::-1]:
    if unite(x, y):
        X = find(x)
        Y = find(y)
        total -= size[X] * size[Y]
        ans += [total]
        if size[X] >= size[Y]:
            X, Y = sorted([X,Y])
        u = [Y if i == X else i for i in u]
        size[Y] += size[X]
        size[X] = 0

    else:
        ans += [total]

print(*ans[m-1::-1], sep="\n")

Fixed submission:
import sys
n , m, *e = map(int,sys.stdin.read().split())
total = n*(n-1)//2
ans =[total]
u = [-1]*(n+1)

def find(x):
    if u[x] < 0 :
        return x
    else:
        return find(u[x])

for x , y in zip(e[-2:1:-2],e[:1:-2]):
    x = find(x)
    y = find(y)
    x, y = sorted((x, y))
    if x != y:
        total -= u[x] * u[y]
        u[x] += u[y]
        u[y] = x
    ans += [total]

print(*ans[::-1], sep="\n")

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n, m = map(int, input().split())
bridge = []
for i in range(m):
    bridge += list(map(int, input().split()))
bridge = np.array(bridge).reshape(m, 2)
total = n*(n-1)//2
ans =[total]
u = [i for i in range(n+1)]
def unite(x, y):
    X = find(x)
    Y = find(y)
    if X != Y:
        return 1
    else:
        return 0

def find(x):
    if x != u[x]:
        x =u[x]
        find(x)
    return x

for x , y in bridge[::-1]:
    if unite(x, y):
        xc = u.count(u[x])
        yc = u.count(u[y])
        total -= xc * yc
        ans += [total]
        if xc >= yc:
            x, y = sorted([x, y])
            u = [find(y) if i == find(x) else i for i in u]
        else:
            u = [find(y) if i == find(x) else i for i in u]
    else:
        ans += [total]

ans = ans[:-1]
print(*ans[::-1], sep="\n")

Fixed submission:
import sys
n , m, *e = map(int,sys.stdin.read().split())
total = n*(n-1)//2
ans =[total]
u = [-1]*(n+1)

def find(x):
    if u[x] < 0 :
        return x
    else:
        return find(u[x])

for x , y in zip(e[-2:1:-2],e[:1:-2]):
    x = find(x)
    y = find(y)
    x, y = sorted((x, y))
    if x != y:
        total -= u[x] * u[y]
        u[x] += u[y]
        u[y] = x
    ans += [total]

print(*ans[::-1], sep="\n")

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n, m = map(int, input().split())
bridge = []
for i in range(m):
    bridge += list(map(int, input().split()))
bridge = np.array(bridge).reshape(m, 2)
total = n*(n-1)//2
ans =[total]
u = [i for i in range(n+1)]
def unite(x, y, total, ans, u):
    X, Y = sorted([find(x), find(y)])
    if X != Y:
        total -= u.count(u[X]) * u.count(u[Y])
        ans += [total]
        u = [Y if i == X else i for i in u]
    else:
        ans += [total]
    return ans, total, u

def find(x):
    if x != u[x]:
        x =u[x]
        find(x)
    return x

def size(x):
    u.count(abs(u[x]))
for x , y in bridge[::-1]:
    ans, total, u = unite(x, y, total, ans, u)

ans = ans[:-1]
print(*ans[::-1], sep="\n")


Fixed submission:
import sys
n , m, *e = map(int,sys.stdin.read().split())
total = n*(n-1)//2
ans =[total]
u = [-1]*(n+1)

def find(x):
    if u[x] < 0 :
        return x
    else:
        return find(u[x])

for x , y in zip(e[-2:1:-2],e[:1:-2]):
    x = find(x)
    y = find(y)
    x, y = sorted((x, y))
    if x != y:
        total -= u[x] * u[y]
        u[x] += u[y]
        u[y] = x
    ans += [total]

print(*ans[::-1], sep="\n")