#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define X first #define Y second #define pb push_back #define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X)) #define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X)) #define repe(X,Y) for ((X) = 0;(X) < (Y);++(X)) #define peat(X,Y) for (;(X) < (Y);++(X)) #define all(X) (X).begin(),(X).end() #define rall(X) (X).rbegin(),(X).rend() #define eb emplace_back #define UNIQUE(X) (X).erase(unique(all(X)),(X).end()) using namespace std; typedef long long ll; typedef pair pii; typedef pair pll; template using vv=vector>; template ostream& operator<<(ostream &os, const vector &t) { os<<"{"; rep(i,t.size()) {os< ostream& operator<<(ostream &os, const pair &t) { return os<<"("< data; UF(int size):data(size,-1){} bool unite(int x,int y){ x=root(x); y=root(y); if(x!=y){ if(data[y]>n>>m; int x,y; UF uf(n); rep(i,m){ cin>>x>>y; --x; --y; uf.unite(x,y); } vector dp(212345,INF); dp[0]=0; rep(i,n) if(uf.data[i]<0) rrep(j,112345) dp[j-uf.data[i]]=min(dp[j-uf.data[i]],1+dp[j]); rep(i,n) cout<<(dp[i+1]==INF?-1:dp[i+1]-1)<