Language: C++

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N, M;
struct edge {int u, v;};

edge es[100005];
int par[100005]; //親
int tree_rank[100005]; //木の深さ

void init_union_find(int n){
  rep(i, n){
    par[i] = i;
    tree_rank[i] = 0;
  }
}

// 木の根を求める
int find(int x){
  if (par[x] == x) return x;
  else return par[x] = find(par[x]);
}

// xとyの属する集合を併合
void unite(int x, int y){
  x = find(x);
  y = find(y);
  if (x == y) return;

  if (tree_rank[x] < tree_rank[y]) par[x] = y;
  else{
    par[y] = x;
    if (tree_rank[x] == tree_rank[y]) tree_rank[x]++;
  }
}

// xとyが同じ要素に属するかどうか
bool same(int x, int y){
  return find(x) == find(y);
}

int main() {
  INCANT;
  cin >> N >> M;
  int x,y,z;
  init_union_find(N);
  rep(i, M) {
    cin >> x >> y >> z;
    x--;y--;
    unite(x,y);
  }
  set<int> S;
  rep(i, N) {
    S.insert(par[i]);
  }
  cout << S.size() << "\n";
  return 0;
}#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N, M;
struct edge {int u, v;};

edge es[100005];
int par[100005]; //親
int tree_rank[100005]; //木の深さ

void init_union_find(int n){
  rep(i, n){
    par[i] = i;
    tree_rank[i] = 0;
  }
}

// 木の根を求める
int find(int x){
  if (par[x] == x) return x;
  else return par[x] = find(par[x]);
}

// xとyの属する集合を併合
void unite(int x, int y){
  x = find(x);
  y = find(y);
  if (x == y) return;

  if (tree_rank[x] < tree_rank[y]) par[x] = y;
  else{
    par[y] = x;
    if (tree_rank[x] == tree_rank[y]) tree_rank[x]++;
  }
}

// xとyが同じ要素に属するかどうか
bool same(int x, int y){
  return find(x) == find(y);
}

int main() {
  INCANT;
  cin >> N >> M;
  int x,y,z;
  init_union_find(N);
  rep(i, M) {
    cin >> x >> y >> z;
    x--;y--;
    unite(x,y);
  }
  set<int> S;
  rep(i, N) {
    S.insert(par[i]);
  }
  cout << S.size() << "\n";
  return 0;
}

Compiler output:
a.cc:77:2: error: stray '#' in program
   77 | }#include <algorithm>
      |  ^
a.cc:77:3: error: 'include' does not name a type
   77 | }#include <algorithm>
      |   ^~~~~~~
a.cc:97:10: error: redefinition of 'const ll MOD'
   97 | const ll MOD = 1e9+7LL;
      |          ^~~
a.cc:21:10: note: 'const ll MOD' previously defined here
   21 | const ll MOD = 1e9+7LL;
      |          ^~~
a.cc:98:11: error: redefinition of 'const int INF'
   98 | const int INF = 2e9;
      |           ^~~
a.cc:22:11: note: 'const int INF' previously defined here
   22 | const int INF = 2e9;
      |           ^~~
a.cc:99:5: error: redefinition of 'int N'
   99 | int N, M;
      |     ^
a.cc:23:5: note: 'int N' previously declared here
   23 | int N, M;
      |     ^
a.cc:99:8: error: redefinition of 'int M'
   99 | int N, M;
      |        ^
a.cc:23:8: note: 'int M' previously declared here
   23 | int N, M;
      |        ^
a.cc:100:8: error: redefinition of 'struct edge'
  100 | struct edge {int u, v;};
      |        ^~~~
a.cc:24:8: note: previous definition of 'struct edge'
   24 | struct edge {int u, v;};
      |        ^~~~
a.cc:102:6: error: redefinition of 'edge es [100005]'
  102 | edge es[100005];
      |      ^~
a.cc:26:6: note: 'edge es [100005]' previously declared here
   26 | edge es[100005];
      |      ^~
a.cc:103:5: error: redefinition of 'int par [100005]'
  103 | int par[100005]; //親
      |     ^~~
a.cc:27:5: note: 'int par [100005]' previously declared here
   27 | int par[100005]; //親
      |     ^~~
a.cc:104:5: error: redefinition of 'int tree_rank [100005]'
  104 | int tree_rank[100005]; //木の深さ
      |     ^~~~~~~~~
a.cc:28:5: note: 'int tree_rank [100005]' previously declared here
   28 | int tree_rank[100005]; //木の深さ
      |     ^~~~~~~~~
a.cc:106:6: error: redefinition of 'void init_union_find(int)'
  106 | void init_union_find(int n){
      |      ^~~~~~~~~~~~~~~
a.cc:30:6: note: 'void init_union_find(int)' previously defined here
   30 | void init_union_find(int n){
      |      ^~~~~~~~~~~~~~~
a.cc:114:5: error: redefinition of 'int find(int)'
  114 | int find(int x){
      |     ^~~~
a.cc:38:5: note: 'int find(int)' previously defined here
   38 | int find(int x){
      |     ^~~~
a.cc:120:6: error: redefinition of 'void unite(int, int)'
  120 | void unite(int x, int y){
      |      ^~~~~
a.cc:44:6: note: 'void unite(int, int)' previously defined here
   44 | void unite(int x, int y){
      |      ^~~~~
a.cc:133:6: error: redefinition of 'bool same(int, int)'
  133 | bool same(int x, int y){
      |      ^~~~
a.cc:57:6: note: 'bool same(int, int)' previously defined here
   57 | bool same(int x, int y){
      |      ^~~~
a.cc:137:5: error: redefinition of 'int main()'
  137 | int main() {
      |     ^~~~
a.cc:61:5: note: 'int main()' previously defined here
   61 | int main() {
      |     ^~~~