#pragma GCC optimize("O3") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using P = pair; using T = tuple; template inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;} template inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;} constexpr int MOD = 1e9 + 7; constexpr int inf = 1e9; constexpr long long INF = 1e18; #define all(a) (a).begin(), (a).end() int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; class UnionFind{ public: vector par; vector rank; vector sz; int uf_size; UnionFind(int n){ par.resize(n); rank.resize(n); sz.resize(n); uf_size = n; for(int i=0; i>n>>a>>b; vector x(n); for(int i=0; i>x[i]; UnionFind uf(n); vector imos(n + 1, 0); for(int i=0; i