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

ans = [-1] * N



def find(x):

    global ans

    if ans[x] == -1:

        return x

    else:

        ans[x] = find(ans[x])

        return ans[x]

    

for _ in range(M):

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

    x -= 1

    y -= 1

    xx = find(x)

    yy = find(y)

    if ans[x] == ans[y] == -1:

        ans[y] = x

    elif xx == yy:

        continue

    else:

        ans[yy] = xx



n = 0

for i in ans:

    if i == -1:

        n += 1



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

UF = [-1] * (N+1)

def find(x):

    global UF

    if UF[x] == -1:

        return x

    else:

        UF[x] = find(UF[x])

        return UF[x]

def union(x,y):

    global UF

    xx = find(x)

    yy = find(y)

    if UF[x] == UF[y] == -1:

        UF[y] = xx

        return

    elif xx == yy:

        return 

    else:

        UF[yy] = xx

        return 

    

for _ in range(M):

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

    union(x,y)

    

print((sum([i < 0 for i in UF[1:]])))
N, M = list(map(int, input().split()))
ans = [-1] * N


def find(x):
    global ans
    if ans[x] == -1:
        return x
    else:
        ans[x] = find(ans[x])
        return ans[x]


for _ in range(M):
    x, y, z = list(map(int, input().split()))
    x -= 1
    y -= 1
    xx = find(x)
    yy = find(y)
    if ans[x] == ans[y] == -1:
        ans[y] = x
    elif xx == yy:
        continue
    else:
        ans[yy] = xx
n = 0
for i in ans:
    if i == -1:
        n += 1
print(n)

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


def find(x):
    global UF
    if UF[x] == -1:
        return x
    else:
        UF[x] = find(UF[x])
        return UF[x]


def union(x, y):
    global UF
    xx = find(x)
    yy = find(y)
    if UF[x] == UF[y] == -1:
        UF[y] = xx
        return
    elif xx == yy:
        return
    else:
        UF[yy] = xx
        return


for _ in range(M):
    x, y, z = list(map(int, input().split()))
    union(x, y)
print((sum([i < 0 for i in UF[1:]])))

-ans = [-1] * N +UF = [-1] * (N + 1) -    global ans -    if ans[x] == -1: +    global UF +    if UF[x] == -1: -        ans[x] = find(ans[x]) -        return ans[x] +        UF[x] = find(UF[x]) +        return UF[x] + + +def union(x, y): +    global UF +    xx = find(x) +    yy = find(y) +    if UF[x] == UF[y] == -1: +        UF[y] = xx +        return +    elif xx == yy: +        return +    else: +        UF[yy] = xx +        return -    x -= 1 -    y -= 1 -    xx = find(x) -    yy = find(y) -    if ans[x] == ans[y] == -1: -        ans[y] = x -    elif xx == yy: -        continue -    else: -        ans[yy] = xx -n = 0 -for i in ans: -    if i == -1: -        n += 1 -print(n) +    union(x, y) +print((sum([i < 0 for i in UF[1:]])))