class UnionFind():

    #ｎは頂点数

    def __init__(self, n):

        self.parent = [-1]*n



    #aの属する集合の根を取得

    def root(self,a):

        if self.parent[a] < 0:return a

        self.parent[a] = self.root(self.parent[a])

        return self.parent[a]

    

    #aの属する集合の要素数を取得

    def size(self,a):

        return -self.parent[self.root(a)]



    #aとbをくっつける

    def connect(self,a,b):

        if self.root(a) == self.root(b):return False

        a = self.root(a);b = self.root(b)

        if self.size(a) < self.size(b):a,b = b,a

        self.parent[a] += self.parent[b]

        self.parent[b] = a

        return True



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

uni = UnionFind(n)

for i in range(m):

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

    x -= 1

    y -= 1

    uni.connect(x,y)

ans = 0

for i in uni.parent:

    if i < 0:

        ans += 1

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

graph = [[] for i in range(n)]

for i in range(m):

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

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

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

check = [True]*n

count = 0

for i in range(n):

    if check[i]:

        count += 1

        stack = []

        stack.append(i)

        check[i] = False

        while stack:

            p = stack.pop()

            for j in graph[p]:

                if check[j]:

                    stack.append(j)

                    check[j] = False

    else:

        continue



print(count)
class UnionFind:
    # ｎは頂点数
    def __init__(self, n):
        self.parent = [-1] * n

    # aの属する集合の根を取得
    def root(self, a):
        if self.parent[a] < 0:
            return a
        self.parent[a] = self.root(self.parent[a])
        return self.parent[a]

    # aの属する集合の要素数を取得
    def size(self, a):
        return -self.parent[self.root(a)]

    # aとbをくっつける
    def connect(self, a, b):
        if self.root(a) == self.root(b):
            return False
        a = self.root(a)
        b = self.root(b)
        if self.size(a) < self.size(b):
            a, b = b, a
        self.parent[a] += self.parent[b]
        self.parent[b] = a
        return True


n, m = list(map(int, input().split()))
uni = UnionFind(n)
for i in range(m):
    x, y, z = list(map(int, input().split()))
    x -= 1
    y -= 1
    uni.connect(x, y)
ans = 0
for i in uni.parent:
    if i < 0:
        ans += 1
print(ans)

n, m = list(map(int, input().split()))
graph = [[] for i in range(n)]
for i in range(m):
    x, y, z = list(map(int, input().split()))
    graph[x - 1].append(y - 1)
    graph[y - 1].append(x - 1)
check = [True] * n
count = 0
for i in range(n):
    if check[i]:
        count += 1
        stack = []
        stack.append(i)
        check[i] = False
        while stack:
            p = stack.pop()
            for j in graph[p]:
                if check[j]:
                    stack.append(j)
                    check[j] = False
    else:
        continue
print(count)

-class UnionFind: -    # ｎは頂点数 -    def __init__(self, n): -        self.parent = [-1] * n - -    # aの属する集合の根を取得 -    def root(self, a): -        if self.parent[a] < 0: -            return a -        self.parent[a] = self.root(self.parent[a]) -        return self.parent[a] - -    # aの属する集合の要素数を取得 -    def size(self, a): -        return -self.parent[self.root(a)] - -    # aとbをくっつける -    def connect(self, a, b): -        if self.root(a) == self.root(b): -            return False -        a = self.root(a) -        b = self.root(b) -        if self.size(a) < self.size(b): -            a, b = b, a -        self.parent[a] += self.parent[b] -        self.parent[b] = a -        return True - - -uni = UnionFind(n) +graph = [[] for i in range(n)] -    x -= 1 -    y -= 1 -    uni.connect(x, y) -ans = 0 -for i in uni.parent: -    if i < 0: -        ans += 1 -print(ans) +    graph[x - 1].append(y - 1) +    graph[y - 1].append(x - 1) +check = [True] * n +count = 0 +for i in range(n): +    if check[i]: +        count += 1 +        stack = [] +        stack.append(i) +        check[i] = False +        while stack: +            p = stack.pop() +            for j in graph[p]: +                if check[j]: +                    stack.append(j) +                    check[j] = False +    else: +        continue +print(count)