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



g = [[] for _ in range(n)]

for i in range(m):

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

	g[x-1].append(y-1)

	g[y-1].append(x-1)



check = [False]*n



cnt=0

import queue

for i in range(n):

	if check[i]:

		continue

	cnt+=1

	check[i]=True

	q=queue.Queue()

	q.put(i)



	while not q.empty():

		now=q.get()

		for ne in g[now]:

			if check[ne]:

				continue

			check[ne]=True

			q.put(ne)



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



g = [[] for _ in range(n)]

for i in range(m):

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

	g[x-1].append(y-1)

	g[y-1].append(x-1)



check = [False]*n



cnt=0

import queue

q=queue.Queue()

for i in range(n):

	if check[i]:

		continue

	cnt+=1

	check[i]=True

	q.put(i)



	while not q.empty():

		now=q.get()

		for ne in g[now]:

			if check[ne]:

				continue

			check[ne]=True

			q.put(ne)



print(cnt)
n, m = list(map(int, input().split()))
g = [[] for _ in range(n)]
for i in range(m):
    x, y, z = list(map(int, input().split()))
    g[x - 1].append(y - 1)
    g[y - 1].append(x - 1)
check = [False] * n
cnt = 0
import queue

for i in range(n):
    if check[i]:
        continue
    cnt += 1
    check[i] = True
    q = queue.Queue()
    q.put(i)
    while not q.empty():
        now = q.get()
        for ne in g[now]:
            if check[ne]:
                continue
            check[ne] = True
            q.put(ne)
print(cnt)

n, m = list(map(int, input().split()))
g = [[] for _ in range(n)]
for i in range(m):
    x, y, z = list(map(int, input().split()))
    g[x - 1].append(y - 1)
    g[y - 1].append(x - 1)
check = [False] * n
cnt = 0
import queue

q = queue.Queue()
for i in range(n):
    if check[i]:
        continue
    cnt += 1
    check[i] = True
    q.put(i)
    while not q.empty():
        now = q.get()
        for ne in g[now]:
            if check[ne]:
                continue
            check[ne] = True
            q.put(ne)
print(cnt)

+q = queue.Queue() -    q = queue.Queue()