#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){ unordered_map r; for(int i=0;i> 31 ) ); } int main(){ const int INF=1<<29; int N,M; scanf("%d%d",&N,&M); union_find uf(N); for(;M--;){ int a,b; scanf("%d%d",&a,&b); uf.unite(a-1,b-1); } vectoredges; uf.enumerate(edges); vectorbag(N+1,INF); bag[0]=-1; int t=0,tbelow,prev=0; for(auto &e:edges){ if(prev!=e)prev=e,tbelow=e; else tbelow+=e; t+=e; for(int i=t;i>=tbelow;i--)if(bag[i-e]