#include using namespace std; using Int = long long; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a r,p; UnionFind(){} UnionFind(int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);} int find(int x){ return (x==p[x]?x:p[x]=find(p[x])); } bool same(int x,int y){ return find(x)==find(y); } void unite(int x,int y){ x=find(x);y=find(y); if(x==y) return; if(r[x]>n>>m; UnionFind uf(n); for(int i=0;i>x>>y; x--;y--; uf.unite(x,y); } vector v; for(int i=0;i cnt(BS,0); using P = pair; vector

vs; for(int x:v){ if(x dp(n+1,INF); dp[0]=0; for(P p:vs){ int d=p.first,c=p.second; vector nx(n+1,INF); for(int i=0;i<=n;i++){ chmin(nx[i],dp[i]); if(i+d<=n) chmin(nx[i+d],dp[i]+c); } swap(dp,nx); } for(int i=1;i<=n;i++){ if(dp[i]==INF) dp[i]=0; cout<