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

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


def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    
    if rank[x] == rank[y]:
        rank[x] += 1
    elif rank[x] < rank[y]:
        x, y = y, x
        
    par[y] = x
    size[x] += size[y]


def same(x, y):
    return find(x) == find(y)


par = list(range(N))
rank = [0] * N
size = [1] * N

ans = [N * (N - 1) // 2] * M
for i, (a, b) in enumerate(X[:0:-1]):
    if same(a - 1, b - 1):
        ans[i + 1] = ans[i]
        continue

    ans[i + 1] = ans[i] - size[find(a - 1)] * size[find(b - 1)]
    unite(a - 1, b - 1)

print(*ans[::-1], sep="\n") N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M list(map(int, input().split())) for _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split X = [list(map(int, input().split())) for _ in range(M)] X [list(map(int, input().split())) for _ in range(M)] def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x] find if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x] par[x] == x par[x] par x x return x x par[x] = find(par[x]) par[x] par x find(par[x]) find par[x] par x return par[x] par[x] par x x x def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    
    if rank[x] == rank[y]:
        rank[x] += 1
    elif rank[x] < rank[y]:
        x, y = y, x
        
    par[y] = x
    size[x] += size[y] unite x = find(x) x find(x) find x y = find(y) y find(y) find y if x == y:
        return
    
     x == y x y return if rank[x] == rank[y]:
        rank[x] += 1
    elif rank[x] < rank[y]:
        x, y = y, x
        
     rank[x] == rank[y] rank[x] rank x rank[y] rank y rank[x] += 1 rank[x] rank x 1 elif rank[x] < rank[y]:
        x, y = y, x
        
     rank[x] < rank[y] rank[x] rank x rank[y] rank y x, y = y, x x y y x par[y] = x par[y] par y x size[x] += size[y] size[x] size x size[y] size y x x y y def same(x, y):
    return find(x) == find(y) same return find(x) == find(y) find(x) == find(y) find(x) find x find(y) find y x x y y par = list(range(N)) par list(range(N)) list range(N) range N rank = [0] * N rank [0] * N [0] 0 N size = [1] * N size [1] * N [1] 1 N ans = [N * (N - 1) // 2] * M ans [N * (N - 1) // 2] * M [N * (N - 1) // 2] N * (N - 1) // 2 N * (N - 1) N N - 1 N 1 2 M for i, (a, b) in enumerate(X[:0:-1]):
    if same(a - 1, b - 1):
        ans[i + 1] = ans[i]
        continue

    ans[i + 1] = ans[i] - size[find(a - 1)] * size[find(b - 1)]
    unite(a - 1, b - 1) i (a, b) a b enumerate(X[:0:-1]) enumerate X[:0:-1] X :0:-1 0 -1 if same(a - 1, b - 1):
        ans[i + 1] = ans[i]
        continue

     same(a - 1, b - 1) same a - 1 a 1 b - 1 b 1 ans[i + 1] = ans[i] ans[i + 1] ans i + 1 i 1 ans[i] ans i continue ans[i + 1] = ans[i] - size[find(a - 1)] * size[find(b - 1)] ans[i + 1] ans i + 1 i 1 ans[i] - size[find(a - 1)] * size[find(b - 1)] ans[i] ans i size[find(a - 1)] * size[find(b - 1)] size[find(a - 1)] size find(a - 1) find a - 1 a 1 size[find(b - 1)] size find(b - 1) find b - 1 b 1 unite(a - 1, b - 1) unite a - 1 a 1 b - 1 b 1 print(*ans[::-1], sep="\n") print *ans[::-1] ans[::-1] ans ::-1 -1 sep="\n" sep "\n" def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    
    if rank[x] == rank[y]:
        rank[x] += 1
    elif rank[x] < rank[y]:
        x, y = y, x
        
    par[y] = x
    size[x] += size[y] def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    
    if rank[x] == rank[y]:
        rank[x] += 1
    elif rank[x] < rank[y]:
        x, y = y, x
        
    par[y] = x
    size[x] += size[y] unite par = list(range(N)) list(range(N)) par def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x] def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x] find M = map(int, input().split()) map(int, input().split()) M def same(x, y):
    return find(x) == find(y) def same(x, y):
    return find(x) == find(y) same size = [1] * N [1] * N size rank = [0] * N [0] * N rank ans = [N * (N - 1) // 2] * M [N * (N - 1) // 2] * M ans X = [list(map(int, input().split())) for _ in range(M)] [list(map(int, input().split())) for _ in range(M)] X N, M = map(int, input().split()) map(int, input().split()) N
N, M = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(M)]

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


def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    
    if rank[x] == rank[y]:
        rank[x] += 1
    elif rank[x] < rank[y]:
        x, y = y, x
        
    par[y] = x
    size[x] += size[y]


def same(x, y):
    return find(x) == find(y)


par = list(range(N))
rank = [0] * N
size = [1] * N

ans = [N * (N - 1) // 2] * M
for i, (a, b) in enumerate(X[:0:-1]):
    if same(a - 1, b - 1):
        ans[i + 1] = ans[i]
        continue

    ans[i + 1] = ans[i] - size[find(a - 1)] * size[find(b - 1)]
    unite(a - 1, b - 1)

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