def find(x):

    if par[x] < 0:

        return x

    else:

        par[x] = find(par[x])

        return par[x]

def unite(x,y):

    x = find(x)

    y = find(y)

    

    if x == y:

        return False

    else:

        if par[x] > par[y]:

            x,y = y,x

        par[x] += par[y]

        par[y] = x

        return True



def same(x,y):

    return find(x) == find(y)



def size(x):

    return -par[find(x)]



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

par = [-1]*n



for i in range(m):

    X,Y,Z = list(map(int,input().split()))

    unite(X-1,Y-1)



tank = set([])

for i in range(n):

    tank.add(find(i))

print((len(tank)))

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





par = [-1]*(n)

def find(x):

    if par[x] < 0:

        return x

    else:

        par[x] = find(par[x]) #経路圧縮

        return par[x]

def same(x,y):

    return find(x) == find(y)

def unite(x,y):

    x = find(x)

    y = find(y)

    if x == y:

        return 0

    else:

      if par[x] > par[y]:x,y = y,x

      par[x] += par[y]

      par[y] = x

def size(x):

    return -par[find(x)]





for i in range(m):

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

  unite(x-1,y-1)





ans = 0

# print(par)

for i in range(n):

  if par[i] <0:

    ans += 1

print(ans)
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]


def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return False
    else:
        if par[x] > par[y]:
            x, y = y, x
        par[x] += par[y]
        par[y] = x
        return True


def same(x, y):
    return find(x) == find(y)


def size(x):
    return -par[find(x)]


n, m = list(map(int, input().split()))
par = [-1] * n
for i in range(m):
    X, Y, Z = list(map(int, input().split()))
    unite(X - 1, Y - 1)
tank = set([])
for i in range(n):
    tank.add(find(i))
print((len(tank)))

n, m = list(map(int, input().split()))
par = [-1] * (n)


def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])  # 経路圧縮
        return par[x]


def same(x, y):
    return find(x) == find(y)


def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return 0
    else:
        if par[x] > par[y]:
            x, y = y, x
        par[x] += par[y]
        par[y] = x


def size(x):
    return -par[find(x)]


for i in range(m):
    x, y, z = list(map(int, input().split()))
    unite(x - 1, y - 1)
ans = 0
# print(par)
for i in range(n):
    if par[i] < 0:
        ans += 1
print(ans)

+n, m = list(map(int, input().split())) +par = [-1] * (n) + + -        par[x] = find(par[x]) +        par[x] = find(par[x])  # 経路圧縮 + + +def same(x, y): +    return find(x) == find(y) -        return False +        return 0 -        return True - - -def same(x, y): -    return find(x) == find(y) -n, m = list(map(int, input().split())) -par = [-1] * n -    X, Y, Z = list(map(int, input().split())) -    unite(X - 1, Y - 1) -tank = set([]) +    x, y, z = list(map(int, input().split())) +    unite(x - 1, y - 1) +ans = 0 +# print(par) -    tank.add(find(i)) -print((len(tank))) +    if par[i] < 0: +        ans += 1 +print(ans)