#include #include #include #include #include using namespace std; class UnionSet { public: #define DP_SIZE 400001 int dp[DP_SIZE]; void unite(int x, int y) { dp[find(x)] = find(y); // printf("In unite: %d %d\n", find(x), find(y)); } int find(int x) { if (dp[x] == x) return x; return dp[x] = find(dp[x]); } void init() { for (int i=0; i> ps(n); map xs, ys; UnionSet us; us.init(); for (int i=0; i tokens; for (int i=0; i