#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 &edges){ map r; for(int i=0;iedges; uf.enumerate(edges); vectorbag(N+1,-1); int t=0,prev=0; for(auto &e:edges){ t+=e; for(int i=t;i>=e;i--)if(i==e||bag[i-e]>=0){ if(bag[i]<0||bag[i]>bag[i-e]+1)bag[i]=bag[i-e]+1; } } for(int i=1;i<=N;i++)printf("%d\n",bag[i]); }