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]))

    rx = root(x)

    ry = root(y)

    if rx < ry:

        xy[rx] = ry

    else:

        xy[ry] = rx



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

    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]))
    rx = root(x)
    ry = root(y)
    if rx < ry:
        xy[rx] = ry
    else:
        xy[ry] = rx
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
    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)

+    a = [] -    xy[x] = i +        a += [i] +    for b in a: +        xy[b] = i -    rx = root(x) -    ry = root(y) -    if rx < ry: -        xy[rx] = ry -    else: -        xy[ry] = rx +    xy[root(x)] = root(y)