r=lambda x:x if u[x]<0else r(u[x])

n,m,*t=list(map(int,open(0).read().split()))

u=[-1]*-~n

for x,y in zip(t[::3],t[1::3]):

 x,y=sorted((r(x),r(y)))

 if x!=y:u[x]+=u[y];u[y]=x

print((sum(i<0for i in u)-1))
r=lambda x:x*(u[x]<0)or r(u[x])

n,m,*t=list(map(int,open(0).read().split()))

u=[-1]*-~n

for x,y in zip(t[::3],t[1::3]):

 x,y=sorted((r(x),r(y)))

 if x!=y:u[x]+=u[y];u[y]=x

print((sum(i<0for i in u)-1))
r = lambda x: x if u[x] < 0 else r(u[x])
n, m, *t = list(map(int, open(0).read().split()))
u = [-1] * -~n
for x, y in zip(t[::3], t[1::3]):
    x, y = sorted((r(x), r(y)))
    if x != y:
        u[x] += u[y]
        u[y] = x
print((sum(i < 0 for i in u) - 1))

r = lambda x: x * (u[x] < 0) or r(u[x])
n, m, *t = list(map(int, open(0).read().split()))
u = [-1] * -~n
for x, y in zip(t[::3], t[1::3]):
    x, y = sorted((r(x), r(y)))
    if x != y:
        u[x] += u[y]
        u[y] = x
print((sum(i < 0 for i in u) - 1))

-r = lambda x: x if u[x] < 0 else r(u[x]) +r = lambda x: x * (u[x] < 0) or r(u[x])