#include using namespace std; #define endl '\n' #define lfs cout<= (ll)(n); i--) using ll = long long; using ld = long double; const ll MOD = 1e9+7; //const ll MOD = 998244353; const ll INF = 1e18; using P = pair; template bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;} template bool chmax(T &a,T b){if(a void ans(bool x,T1 y,T2 z){if(x)cout< void debug(vector>&v,ll h,ll w){for(ll i=0;i&v,ll h,ll w){for(ll i=0;i void debug(vector&v,ll n){if(n!=0)cout< vector>vec(ll x, ll y, T w){ vector>v(x,vector(y,w));return v;} ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;} vectordx={1,0,-1,0,1,1,-1,-1}; vectordy={0,1,0,-1,1,-1,1,-1}; template vector make_v(size_t a,T b){return vector(a,b);} template auto make_v(size_t a,Ts... ts){ return vector(a,make_v(ts...)); } ostream &operator<<(ostream &os, pair&p){ return os << p.first << " " << p.second; } vectordist(200001); void bfs(ll k,vector>&g){ queue

q; ll n=g.size(); q.emplace(k,0); fill(dist.begin(),dist.begin()+n,INF); while(!q.empty()){ ll x=q.front().fi; ll len=q.front().se; if(dist[x]==INF){ dist[x]=len; for(ll i=0;i>n>>k; if(k>n){ cout<<-1<>g(n); rep(i,0,n-1){ ll a,b;cin>>a>>b;a--;b--; g[a].PB(b); g[b].PB(a); } bfs(0,g); vectord; rep(i,0,n)d.PB(dist[i]); sort(ALL(d)); rep(i,0,k)res+=d[i]; cout<