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

root=[-1]*N

def search(i):

    if root[i]>=0:

        root[i]=search(root[i])

        return root[i]

    return i

for i in range(M):

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

    x-=1

    y-=1

    rx=search(x)

    ry=search(y)

    if rx==ry:

        continue

    elif root[rx]<=root[ry]:

        root[ry]+=root[rx]

        root[rx]=ry

    else:

        root[rx]+=root[ry]

        root[ry]=rx

ans=0

for i in range(N):

    if root[i]<0:

        ans+=1

print(ans)

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

root=[-1]*N

def find(i):

    global root

    if root[i]>=0:

        root[i]=find(root[i])

        return root[i]

    return i

for i in range(M):

    X,Y,Z=list(map(int,input().split()))

    rx=find(X-1)

    ry=find(Y-1)

    if rx==ry:

        continue

    elif root[rx]<=root[ry]:

        root[rx]+=root[ry]

        root[ry]=rx

    elif root[rx]>root[ry]:

        root[ry]+=root[rx]

        root[rx]=ry

ans=0

for r in root:

    if r<0:

        ans+=1

print(ans)
N, M = list(map(int, input().split()))
root = [-1] * N


def search(i):
    if root[i] >= 0:
        root[i] = search(root[i])
        return root[i]
    return i


for i in range(M):
    x, y, z = list(map(int, input().split()))
    x -= 1
    y -= 1
    rx = search(x)
    ry = search(y)
    if rx == ry:
        continue
    elif root[rx] <= root[ry]:
        root[ry] += root[rx]
        root[rx] = ry
    else:
        root[rx] += root[ry]
        root[ry] = rx
ans = 0
for i in range(N):
    if root[i] < 0:
        ans += 1
print(ans)

N, M = list(map(int, input().split()))
root = [-1] * N


def find(i):
    global root
    if root[i] >= 0:
        root[i] = find(root[i])
        return root[i]
    return i


for i in range(M):
    X, Y, Z = list(map(int, input().split()))
    rx = find(X - 1)
    ry = find(Y - 1)
    if rx == ry:
        continue
    elif root[rx] <= root[ry]:
        root[rx] += root[ry]
        root[ry] = rx
    elif root[rx] > root[ry]:
        root[ry] += root[rx]
        root[rx] = ry
ans = 0
for r in root:
    if r < 0:
        ans += 1
print(ans)

-def search(i): +def find(i): +    global root -        root[i] = search(root[i]) +        root[i] = find(root[i]) -    x, y, z = list(map(int, input().split())) -    x -= 1 -    y -= 1 -    rx = search(x) -    ry = search(y) +    X, Y, Z = list(map(int, input().split())) +    rx = find(X - 1) +    ry = find(Y - 1) +        root[rx] += root[ry] +        root[ry] = rx +    elif root[rx] > root[ry]: -    else: -        root[rx] += root[ry] -        root[ry] = rx -for i in range(N): -    if root[i] < 0: +for r in root: +    if r < 0: