Language: C++

#include <iostream>
#include <vector>
using namespace std;

void D_Show_c_d_i_g(const vector<vector<int>>& c_d_i_g) {
	cout << "cards_divided_into_groups" << endl;
	cout << "size:" << c_d_i_g.size() << endl;
	for (int i = 0; i < c_d_i_g.size(); i++) {
		for (int j = 0; j < c_d_i_g[i].size(); j++) {
			cout << "c_d_i_g[" << i << "]" << c_d_i_g[i][j] << endl;
		}
	}
	cout << endl;
}
void D_Show_g_t(const vector<int>&  g_t) {
	cout << "group_table" << endl;
	for (int i = 0; i < g_t.size(); i++) {
		cout << "[" << i << "] " << g_t[i] << endl;
	}
	cout << endl;
}

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> group_table(N+1, -1);//用いるのは1~Nの要素 i番目のカードの属するグループNoを格納
	vector<vector<int>> cards_divided_into_groups;
	int group_counter = 0;

	//以下のfor文でヒントの出ているものについてのグループ化が終了
	for (int i = 0; i < M; i++) {
		int X, Y, Z;
		cin >> X >> Y >> Z; //X番目とY番目のカードの和がZ
		//両方未登録
		if (group_table[X] == -1 && group_table[Y] == -1) {
			vector<int> cards_group;
			group_table[X] = group_counter;
			group_table[Y] = group_counter;
			cards_group.push_back(X);
			cards_group.push_back(Y);
			cards_divided_into_groups.push_back(cards_group);
			//cards_group.clear();
			group_counter++;
		}
		//片方が登録済
		else if (group_table[X] != -1 && group_table[Y] == -1) {
			group_table[Y] = group_table[X];
			cards_divided_into_groups[group_table[X]].push_back(Y);
		}
		else if (group_table[X] == -1 && group_table[Y] != -1) {
			group_table[X] = group_table[Y];
			cards_divided_into_groups[group_table[Y]].push_back(X);
		}
		//両方が登録済み
		else{
			int group_absorber, group_absorbed;
			if (group_table[X].size() < group_table[Y].size()) {
				group_absorber = group_table[X];
				group_absorbed = group_table[Y];
			}
			else if (group_table[X].size() > group_table[Y].size()) {
				group_absorber = group_table[Y];
				group_absorbed = group_table[X];
			}
			else {
				continue;
			}
			for (auto itr = cards_divided_into_groups[group_absorbed].begin(); itr != cards_divided_into_groups[group_absorbed].end(); itr++) {
				cards_divided_into_groups[group_absorber].push_back(*itr);
				group_table[*itr] = group_absorber;
			}
			cards_divided_into_groups.erase(cards_divided_into_groups.begin() + group_absorbed);
			for (int i = 1; i <= N; i++) {
				if (group_table[i] > group_absorbed) group_table[i]--;
			}
			group_counter--;
		}
	//	cout << "Result" << endl;
	//	D_Show_g_t(group_table);
	//	D_Show_c_d_i_g(cards_divided_into_groups);
	}
	//ヒントの出ていないもののカウント
	unsigned int no_hint_count = 0;
	for (int i = 1; i <= N; i++) {
		if (group_table[i] == -1) no_hint_count++;
	}
	cout << cards_divided_into_groups.size() + no_hint_count << endl;
	
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:57:44: error: request for member 'size' in 'group_table.std::vector<int>::operator[](((std::vector<int>::size_type)X))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   57 |                         if (group_table[X].size() < group_table[Y].size()) {
      |                                            ^~~~
a.cc:57:68: error: request for member 'size' in 'group_table.std::vector<int>::operator[](((std::vector<int>::size_type)Y))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   57 |                         if (group_table[X].size() < group_table[Y].size()) {
      |                                                                    ^~~~
a.cc:61:49: error: request for member 'size' in 'group_table.std::vector<int>::operator[](((std::vector<int>::size_type)X))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   61 |                         else if (group_table[X].size() > group_table[Y].size()) {
      |                                                 ^~~~
a.cc:61:73: error: request for member 'size' in 'group_table.std::vector<int>::operator[](((std::vector<int>::size_type)Y))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   61 |                         else if (group_table[X].size() > group_table[Y].size()) {
      |                                                                         ^~~~