Language: C++

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

typedef long long LL;
#define CY 505
#define NODE 1005

int ar[CY][CY], f[CY], r[CY];
int N, idx;

void input(int n) {
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			scanf("%d", &ar[i][j]);
		}
	}
}

void init_set(int n) {
	for (int i = 0; i < n; ++i) {
		f[i] = i;
		r[i] = 0;
	}
}

int find_set(int u) {
	if (u != f[u])
		f[u] = find_set(f[u]);
	return f[u];
}

void union_set(int u, int v) {
	if (r[u] >= r[v]) {
		if (r[u] == r[v])
			r[u]++;
		f[v] = u;
	} else {
		f[u] = v;
	}
}

void solve(int n) {
	idx = 0;
	for (int k = 0; k < 31; ++k) {
		int p = 1 << k;
		init_set(2 * n);
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				if (i == j)
					continue;
				int num = p & ar[i][j];
				if ((i & 1) && (j & 1)) {
					if (num) {
						int u = find_set(f[i]);
						int v = find_set(f[j * 2]);
						if (u != v) {
							union_set(u, v);
						}
						int u = find_set(f[i * 2]);
						int v = find_set(f[j]);
						if (u != v) {
							union_set(u, v);
						}
					} else {
						int u = find_set(f[i]);
						int v = find_set(f[j]);
						if (u != v) {
							union_set(u, v);
						}
					}
				} else if ((i & 1) == 0 && (j & 1) == 0) {
					if (num) {
						int u = find_set(f[i * 2]);
						int v = find_set(f[j * 2]);
						if (u != v) {
							union_set(u, v);
						}
					} else {
						int u = find_set(f[i * 2]);
						int v = find_set(f[j]);
						if (u != v) {
							union_set(u, v);
						}
						int u = find_set(f[i]);
						int v = find_set(f[j * 2]);
						if (u != v) {
							union_set(u, v);
						}
					}
				} else {
					if (num) {
						int u = find_set(f[i * 2]);
						int v = find_set(f[j]);
						if (u != v) {
							union_set(u, v);
						}
						int u = find_set(f[i]);
						int v = find_set(f[j * 2]);
						if (u != v) {
							union_set(u, v);
						}
					} else {
						int u = find_set(f[i]);
						int v = find_set(f[j]);
						if (u != v) {
							union_set(u, v);
						}
						int u = find_set(f[i * 2]);
						int v = find_set(f[j * 2]);
						if (u != v) {
							union_set(u, v);
						}
					}
				}
			}
		}
		sort(e, e + idx, cmp);
	}
}

int main(void) {
	while (~scanf("%d", &N)) {
		input(N);
		solve(N);
	}
	return 0;
}

Compiler output:
a.cc: In function 'void solve(int)':
a.cc:70:53: error: redeclaration of 'int u'
   70 |                                                 int u = find_set(f[i * 2]);
      |                                                     ^
a.cc:65:53: note: 'int u' previously declared here
   65 |                                                 int u = find_set(f[i]);
      |                                                     ^
a.cc:71:53: error: redeclaration of 'int v'
   71 |                                                 int v = find_set(f[j]);
      |                                                     ^
a.cc:66:53: note: 'int v' previously declared here
   66 |                                                 int v = find_set(f[j * 2]);
      |                                                     ^
a.cc:95:53: error: redeclaration of 'int u'
   95 |                                                 int u = find_set(f[i]);
      |                                                     ^
a.cc:90:53: note: 'int u' previously declared here
   90 |                                                 int u = find_set(f[i * 2]);
      |                                                     ^
a.cc:96:53: error: redeclaration of 'int v'
   96 |                                                 int v = find_set(f[j * 2]);
      |                                                     ^
a.cc:91:53: note: 'int v' previously declared here
   91 |                                                 int v = find_set(f[j]);
      |                                                     ^
a.cc:108:53: error: redeclaration of 'int u'
  108 |                                                 int u = find_set(f[i]);
      |                                                     ^
a.cc:103:53: note: 'int u' previously declared here
  103 |                                                 int u = find_set(f[i * 2]);
      |                                                     ^
a.cc:109:53: error: redeclaration of 'int v'
  109 |                                                 int v = find_set(f[j * 2]);
      |                                                     ^
a.cc:104:53: note: 'int v' previously declared here
  104 |                                                 int v = find_set(f[j]);
      |                                                     ^
a.cc:119:53: error: redeclaration of 'int u'
  119 |                                                 int u = find_set(f[i * 2]);
      |                                                     ^
a.cc:114:53: note: 'int u' previously declared here
  114 |                                                 int u = find_set(f[i]);
      |                                                     ^
a.cc:120:53: error: redeclaration of 'int v'
  120 |                                                 int v = find_set(f[j * 2]);
      |                                                     ^
a.cc:115:53: note: 'int v' previously declared here
  115 |                                                 int v = find_set(f[j]);
      |                                                     ^
a.cc:128:22: error: 'e' was not declared in this scope
  128 |                 sort(e, e + idx, cmp);
      |                      ^
a.cc:128:34: error: 'cmp' was not declared in this scope; did you mean 'bcmp'?
  128 |                 sort(e, e + idx, cmp);
      |                                  ^~~
      |                                  bcmp