Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())

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


def find(x):
  if par[x]==x:
    return par[x]
  else:
    par[x]=find(par[x])
    return par[x]


def union(x,y):
  fx=find(x)
  fy=find(y)
  if fx!=fy:
    par[fx]=fy


for i in range(m):
  x,y,z=map(int,input().split())
  union(x-1,y-1)

ans=0

for i in range(n):
    if i==find(i):
        ans+=1

print(ans)



Fixed submission:
n,m=map(int,input().split())

par=[i for i in range(n)]
size=[1]*n

def find(x):
  if par[x]==x:
    return x
  else:
    par[x]=find(par[x])
    return par[x]
def union(a,b):
  x=find(a)
  y=find(b)
  if x!=y:
    if size[x]<size[y]:
      par[x]=par[y]
      size[y]+=size[x]
    else: 
      par[y]=par[x]
      size[x]+=size[y]
  else:
    return

for i in range(m):
  x,y,z=map(int,input().split())
  union(x-1,y-1)


ans={find(i) for i in range(n)}

print(len(ans))

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())

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

visited=[False]*n

def find(x):
  if par[x]==x:
    return par[x]
  else:
    par[x]=find(par[x])
    return par[x]


def find2(x):
  visited[x]=True
  if par[x]==x:
    return par[x]
  else:
    par[x]=find2(par[x])
    return par[x]

def union(x,y):
  fx=find(x)
  fy=find(y)
  if fx!=fy:
    par[fx]=fy

ans=-1

for i in range(m):
  x,y,z=map(int,input().split())
  union(x-1,y-1)

cnt=0

for i in range(n):
  if visited[i]==False:
    cnt+=1
    find2(i)


ans=min(cnt,len(set(par)))


print(ans)

Fixed submission:
n,m=map(int,input().split())

par=[i for i in range(n)]
size=[1]*n

def find(x):
  if par[x]==x:
    return x
  else:
    par[x]=find(par[x])
    return par[x]
def union(a,b):
  x=find(a)
  y=find(b)
  if x!=y:
    if size[x]<size[y]:
      par[x]=par[y]
      size[y]+=size[x]
    else: 
      par[y]=par[x]
      size[x]+=size[y]
  else:
    return

for i in range(m):
  x,y,z=map(int,input().split())
  union(x-1,y-1)


ans={find(i) for i in range(n)}

print(len(ans))

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())

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

visited=[False]*n

def find(x):
  if par[x]==x:
    return par[x]
  else:
    par[x]=find(par[x])
    return par[x]


def find2(x):
  visited[x]=True
  if par[x]==x:
    return par[x]
  else:
    par[x]=find2(par[x])
    return par[x]

def union(x,y):
  fx=find(x)
  fy=find(y)
  if fx!=fy:
    par[fx]=fy

ans=-1

for i in range(m):
  x,y=map(int,input().split())
  union(x-1,y-1)

cnt=0

for i in range(n):
  if visited[i]==False:
    cnt+=1
    find2(i)


ans=min(cnt,len(set(par)))


print(ans)


Fixed submission:
n,m=map(int,input().split())

par=[i for i in range(n)]
size=[1]*n

def find(x):
  if par[x]==x:
    return x
  else:
    par[x]=find(par[x])
    return par[x]
def union(a,b):
  x=find(a)
  y=find(b)
  if x!=y:
    if size[x]<size[y]:
      par[x]=par[y]
      size[y]+=size[x]
    else: 
      par[y]=par[x]
      size[x]+=size[y]
  else:
    return

for i in range(m):
  x,y,z=map(int,input().split())
  union(x-1,y-1)


ans={find(i) for i in range(n)}

print(len(ans))

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())

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

visited=[False]*n

def find(x):
  if par[x]==x:
    return par[x]
  else:
    par[x]=find(par[x])
    return par[x]


def union(x,y):
  fx=find(x)
  fy=find(y)
  if fx!=fy:
    par[fx]=fy

ans=-1

for i in range(m):
  x,y,z=map(int,input().split())
  union(x-1,y-1)


ans={find(i) for i in range(n)}

print(len(ans))


Fixed submission:
n,m=map(int,input().split())

par=[i for i in range(n)]
size=[1]*n

def find(x):
  if par[x]==x:
    return x
  else:
    par[x]=find(par[x])
    return par[x]
def union(a,b):
  x=find(a)
  y=find(b)
  if x!=y:
    if size[x]<size[y]:
      par[x]=par[y]
      size[y]+=size[x]
    else: 
      par[y]=par[x]
      size[x]+=size[y]
  else:
    return

for i in range(m):
  x,y,z=map(int,input().split())
  union(x-1,y-1)


ans={find(i) for i in range(n)}

print(len(ans))

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())

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

visited=[False]*n

def find(x):
  if par[x]==x:
    return par[x]
  else:
    par[x]=find(par[x])
    return par[x]


def find2(x):
  visited[x]=True
  if par[x]==x:
    return par[x]
  else:
    par[x]=find2(par[x])
    return par[x]

def union(x,y):
  fx=find(x)
  fy=find(y)
  if fx!=fy:
    par[fx]=fy

ans=-1

for i in range(m):
  x,y,z=map(int,input().split())
  union(x-1,y-1)

ans=1

for i in range(n):
  if visited[i]==False:
    ans+=1
    find2(i)

print(min(ans,len(set(par))))

Fixed submission:
n,m=map(int,input().split())

par=[i for i in range(n)]
size=[1]*n

def find(x):
  if par[x]==x:
    return x
  else:
    par[x]=find(par[x])
    return par[x]
def union(a,b):
  x=find(a)
  y=find(b)
  if x!=y:
    if size[x]<size[y]:
      par[x]=par[y]
      size[y]+=size[x]
    else: 
      par[y]=par[x]
      size[x]+=size[y]
  else:
    return

for i in range(m):
  x,y,z=map(int,input().split())
  union(x-1,y-1)


ans={find(i) for i in range(n)}

print(len(ans))