n, m = list(map(int, input().split()))



xy = [i for i in range(n + 1)]





def root(x):

    i = x

    a = []

    while i != xy[i]:

        i = xy[i]

        a += [i]

    for b in a:

        xy[b] = i

    return i





for _ in range(m):

    x, y = list(map(int, input().split()[:2]))

    xy[root(x)] = root(y)



ans = sum(i == v for i, v in enumerate(xy)) - 1



print(ans)

n, m = list(map(int, input().split()))



xy = [i for i in range(n + 1)]





def root(x):

    i = x

    while i != xy[i]:

        i = xy[i]

    xy[x] = i

    return i





for _ in range(m):

    x, y = list(map(int, input().split()[:2]))

    xy[root(x)] = root(y)



print((sum(i == v for i, v in enumerate(xy)) - 1))

n, m = list(map(int, input().split()))
xy = [i for i in range(n + 1)]


def root(x):
    i = x
    a = []
    while i != xy[i]:
        i = xy[i]
        a += [i]
    for b in a:
        xy[b] = i
    return i


for _ in range(m):
    x, y = list(map(int, input().split()[:2]))
    xy[root(x)] = root(y)
ans = sum(i == v for i, v in enumerate(xy)) - 1
print(ans)

n, m = list(map(int, input().split()))
xy = [i for i in range(n + 1)]


def root(x):
    i = x
    while i != xy[i]:
        i = xy[i]
    xy[x] = i
    return i


for _ in range(m):
    x, y = list(map(int, input().split()[:2]))
    xy[root(x)] = root(y)
print((sum(i == v for i, v in enumerate(xy)) - 1))

-    a = [] -        a += [i] -    for b in a: -        xy[b] = i +    xy[x] = i -ans = sum(i == v for i, v in enumerate(xy)) - 1 -print(ans) +print((sum(i == v for i, v in enumerate(xy)) - 1))