Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
bridge=[]
size=[1]*(N+1)
tree=list(range(N+1))
def find(a):
    x=tree[a]
    if a==x:
        return a
    y=find(x)
    tree[a]=y
    return y
for i in range(M):
    A,B=map(int,input().split())
    bridge.append((A,B))
Ans=N*(N-1)//2
ans=[]
for a,b in bridge[::-1]:
    aroot=find(a)
    broot=find(b)
    if aroot==broot:
        ans.append(Ans)
        continue
    ans.append(Ans)
    Ans-=size[aroot]*size[broot]
    tree[broot]=aroot
    size[aroot]+=size[broot]
for i in ans[::-1]:
    print(i)

Fixed submission:
N,M=map(int,input().split())
bridge=[]
size=[1]*(N+1)
tree=list(range(N+1))
def find(a):
    x=tree[a]
    if a==x:
        return a
    y=find(x)
    tree[a]=y
    return y
for i in range(M):
    A,B=map(int,input().split())
    bridge.append((A,B))
Ans=N*(N-1)//2
ans=[]
for a,b in bridge[::-1]:
    aroot=find(a)
    broot=find(b)
    if aroot==broot:
        ans.append(Ans)
        continue
    ans.append(Ans)
    sa=size[aroot]
    sb=size[broot]
    Ans-=sa*sb
    if sa>sb:
        tree[broot]=aroot
        size[aroot]+=sb
    else:
        tree[aroot]=broot
        size[broot]+=sa
for i in ans[::-1]:
    print(i)

Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
bridge=[]
size=[1]*(N+1)
tree=list(range(N+1))
def find(a):
    x=tree[a]
    if a==x:
        return a
    x=find(x)
    tree[a]=x
    return x
for i in range(M):
    A,B=map(int,input().split())
    bridge.append((A,B))
Ans=N*(N-1)//2
ans=[]
for a,b in bridge[::-1]:
    aroot=find(a)
    broot=find(b)
    if aroot==broot:
        ans.append(Ans)
        continue
    ans.append(Ans)
    Ans-=size[aroot]*size[broot]
    tree[broot]=aroot
    size[aroot]+=size[broot]
for i in ans[::-1]:
    print(i)

Fixed submission:
N,M=map(int,input().split())
bridge=[]
size=[1]*(N+1)
tree=list(range(N+1))
def find(a):
    x=tree[a]
    if a==x:
        return a
    y=find(x)
    tree[a]=y
    return y
for i in range(M):
    A,B=map(int,input().split())
    bridge.append((A,B))
Ans=N*(N-1)//2
ans=[]
for a,b in bridge[::-1]:
    aroot=find(a)
    broot=find(b)
    if aroot==broot:
        ans.append(Ans)
        continue
    ans.append(Ans)
    sa=size[aroot]
    sb=size[broot]
    Ans-=sa*sb
    if sa>sb:
        tree[broot]=aroot
        size[aroot]+=sb
    else:
        tree[aroot]=broot
        size[broot]+=sa
for i in ans[::-1]:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
tree=[[]for i in range(N)]
bridge=[]
for i in range(M):
    A,B=map(int,input().split())
    tree[A-1].append(B-1)
    tree[B-1].append(A-1)
    bridge.append((A,B))
ans=[]
All=N*(N-1)//2
for a,b in bridge:
    ischecked=[0]*N
    tree[a-1].pop(0)
    tree[b-1].pop(0)
    x=0
    for i in range(N):
        if ischecked[i]==1:
            continue
        count=0
        q=[i]
        while q:
            now=q.pop()
            if ischecked[now]==1:
                continue
            ischecked[now]=1
            q.extend(tree[now])
            count+=1
        x+=count*(count-1)//2
    ans.append(All-x)
for i in ans:
    print(i)

Fixed submission:
N,M=map(int,input().split())
bridge=[]
size=[1]*(N+1)
tree=list(range(N+1))
def find(a):
    x=tree[a]
    if a==x:
        return a
    y=find(x)
    tree[a]=y
    return y
for i in range(M):
    A,B=map(int,input().split())
    bridge.append((A,B))
Ans=N*(N-1)//2
ans=[]
for a,b in bridge[::-1]:
    aroot=find(a)
    broot=find(b)
    if aroot==broot:
        ans.append(Ans)
        continue
    ans.append(Ans)
    sa=size[aroot]
    sb=size[broot]
    Ans-=sa*sb
    if sa>sb:
        tree[broot]=aroot
        size[aroot]+=sb
    else:
        tree[aroot]=broot
        size[broot]+=sa
for i in ans[::-1]:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
tree=[[]for i in range(N)]
bridge=[]
for i in range(M):
    A,B=map(int,input().split())
    tree[A-1].append(B-1)
    tree[B-1].append(A-1)
    bridge.append((A,B))
ans=[]
All=N*(N-1)//2
for a,b in bridge:
    ischecked=[0]*N
    tree[a-1].pop(0)
    tree[b-1].pop(0)
    x=0
    for i in range(N):
        if ischecked[i]==1:
            continue
        count=0
        q=[i]
        while q:
            now=q.pop()
            if ischecked[now]==1:
                continue
            ischecked[now]=1
            q.extend(tree[now])
            count+=1
        x+=count*(count-1)//2
    ans.append(All-x)
for i in ans:
    print(i)

Fixed submission:
N,M=map(int,input().split())
bridge=[]
size=[1]*(N+1)
tree=list(range(N+1))
def find(a):
    x=tree[a]
    if a==x:
        return a
    y=find(x)
    tree[a]=y
    return y
for i in range(M):
    A,B=map(int,input().split())
    bridge.append((A,B))
Ans=N*(N-1)//2
ans=[]
for a,b in bridge[::-1]:
    aroot=find(a)
    broot=find(b)
    if aroot==broot:
        ans.append(Ans)
        continue
    ans.append(Ans)
    sa=size[aroot]
    sb=size[broot]
    Ans-=sa*sb
    if sa>sb:
        tree[broot]=aroot
        size[aroot]+=sb
    else:
        tree[aroot]=broot
        size[broot]+=sa
for i in ans[::-1]:
    print(i)