int f[/*size*/]; int find(int x) { return (f[x] == x) ? x : (f[x] = find(f[x])); } void merge(int x, int y) { int fx = find(x), fy = find(y); f[fx] = fy; } bool query(int x, int y) { return find(x) == find(y); }