#include #include #include #include using namespace std; class union_find{ int *parent,*rank,n; public: int root(int a){return parent[a]==a?a:(parent[a]=root(parent[a]));} union_find(int _n){n=_n;parent=new int[n];rank=new int[n];for(int i=0;i &sizes){ unordered_map r; for(int i=0;isizes; uf.enumerate(sizes); vectorbag(N+1,N); bag[0]=-1; int t=0; for(auto &e:sizes){ int n=e.second; #if 1 for(int d=1;n;d*=2){ int x=min(d,n); n-=x; int y=e.first*x; t+=y; for(int i=t;i>=y;i--)if(bag[i-y]=e.first;i--)if(bag[i-e.first]