def find(x):

    while G[x][0]!=x:

        x = G[x][0]

    return x

def union(x,y):

    xa = find(x)

    ya = find(y)

    if G[xa][1]>=G[ya][1]:

        G[ya][0] = xa

        G[xa][1] = max(G[xa][1],G[ya][1]+1)

    else:

        G[xa][0] = ya

        G[ya][1] = max(G[ya][1],G[xa][1]+1)

N,M = list(map(int,input().split()))

G = {i:[i,0] for i in range(1,N+1)}

for _ in range(M):

    x,y,z = list(map(int,input().split()))

    union(x,y)

hist = [0 for _ in range(N+1)]

for i in range(1,N+1):

    x = find(i)

    hist[x] = 1

print((sum(hist)))
def find(x):

    while x!=T[x][0]:

        x = T[x][0]

    return x

def union(x,y):

    a = find(x)

    b = find(y)

    if T[a][1]>T[b][1]:

        T[b][0] = a

    elif T[a][1]==T[b][1]:

        T[b][0] = a

        T[a][1] += 1

    else:

        T[a][0] = b

N,M = list(map(int,input().split()))

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

T = {i:[i,1] for i in range(1,N+1)}

for j in range(M):

    x,y,z = A[j]

    a = find(x)

    b = find(y)

    if a!=b:

        union(a,b)

C = [0 for _ in range(N+1)]

for i in range(1,N+1):

    a = find(i)

    if C[a]==0:

        C[a] = 1

print((sum(C)))
def find(x):
    while G[x][0] != x:
        x = G[x][0]
    return x


def union(x, y):
    xa = find(x)
    ya = find(y)
    if G[xa][1] >= G[ya][1]:
        G[ya][0] = xa
        G[xa][1] = max(G[xa][1], G[ya][1] + 1)
    else:
        G[xa][0] = ya
        G[ya][1] = max(G[ya][1], G[xa][1] + 1)


N, M = list(map(int, input().split()))
G = {i: [i, 0] for i in range(1, N + 1)}
for _ in range(M):
    x, y, z = list(map(int, input().split()))
    union(x, y)
hist = [0 for _ in range(N + 1)]
for i in range(1, N + 1):
    x = find(i)
    hist[x] = 1
print((sum(hist)))

def find(x):
    while x != T[x][0]:
        x = T[x][0]
    return x


def union(x, y):
    a = find(x)
    b = find(y)
    if T[a][1] > T[b][1]:
        T[b][0] = a
    elif T[a][1] == T[b][1]:
        T[b][0] = a
        T[a][1] += 1
    else:
        T[a][0] = b


N, M = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(M)]
T = {i: [i, 1] for i in range(1, N + 1)}
for j in range(M):
    x, y, z = A[j]
    a = find(x)
    b = find(y)
    if a != b:
        union(a, b)
C = [0 for _ in range(N + 1)]
for i in range(1, N + 1):
    a = find(i)
    if C[a] == 0:
        C[a] = 1
print((sum(C)))

-    while G[x][0] != x: -        x = G[x][0] +    while x != T[x][0]: +        x = T[x][0] -    xa = find(x) -    ya = find(y) -    if G[xa][1] >= G[ya][1]: -        G[ya][0] = xa -        G[xa][1] = max(G[xa][1], G[ya][1] + 1) +    a = find(x) +    b = find(y) +    if T[a][1] > T[b][1]: +        T[b][0] = a +    elif T[a][1] == T[b][1]: +        T[b][0] = a +        T[a][1] += 1 -        G[xa][0] = ya -        G[ya][1] = max(G[ya][1], G[xa][1] + 1) +        T[a][0] = b -G = {i: [i, 0] for i in range(1, N + 1)} -for _ in range(M): -    x, y, z = list(map(int, input().split())) -    union(x, y) -hist = [0 for _ in range(N + 1)] +A = [list(map(int, input().split())) for _ in range(M)] +T = {i: [i, 1] for i in range(1, N + 1)} +for j in range(M): +    x, y, z = A[j] +    a = find(x) +    b = find(y) +    if a != b: +        union(a, b) +C = [0 for _ in range(N + 1)] -    x = find(i) -    hist[x] = 1 -print((sum(hist))) +    a = find(i) +    if C[a] == 0: +        C[a] = 1 +print((sum(C)))