#include using namespace std; using ll = long long; #define rep(i,n) for (int i=0;i<(int)(n);i++) int fr(pair &a,pair &b){ return (a.first-b.first)*(a.first-b.first)+(a.second-b.second)*(a.second-b.second); } pair MKsn(pair &a,pair &b){ return make_pair((a.first+b.first)/2,(a.second+b.second)/2); } unsigned int randxor(){ static unsigned int x=123456789,y=362436069,z=521288629,w=88675123; unsigned int t=(x^(x<<11)); x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) ); } vector> d(110,vector(110,0)); vector> v(110); ll cost_calc(vector> &ans,vector> &ccd){ double cost=0; int flg=0; int bf=-1; for(auto [x,i]:ans){ if(bf!=-1){ if(x==1){ if(flg){ cost+=fr(v.at(i),ccd.at(bf))*5; flg=0; } else cost+=d.at(bf).at(i)*25; }else{ if(flg) cost+=fr(ccd.at(i),ccd.at(bf)); else{ cost+=fr(ccd.at(i),v.at(bf))*5; flg=1; } } } bf=i; } return round(1e9/(1000+sqrt(cost))); } ll Scost_calc(vector> &ans){ double cost=0; int bf=-1; for(auto [x,i]:ans){ if(bf!=-1){ cost+=d.at(bf).at(i)*25; } bf=i; } return round(1e9/(1000+sqrt(cost))); } int main(){ auto start_time = std::chrono::system_clock::now(); ios::sync_with_stdio(false); std::cin.tie(nullptr); int n,m; cin>>n>>m; vector> v(n); rep(i,n){ cin>>v.at(i).first>>v.at(i).second; } rep(i,n){ for(int j=i+1;j stl(n,0); vector> ccd(m,{0,0}); vector> ans; ans.emplace_back(1,0); stl.at(0)=1; int nw=0; rep(i,n-1){ int mn=1e9; int mnct=-1; rep(j,n){ if(stl.at(j)) continue; if(mn>d.at(nw).at(j)){ mn=d.at(nw).at(j); mnct=j; } } if(mnct==-1){ break; } stl.at(mnct)=1; ans.emplace_back(1,mnct); nw=mnct; } ans.emplace_back(1,0); ll nwcost=Scost_calc(ans); const unsigned int inf=-1; const double start_temp=10; const double end_temp=0; const int lim_time=100; int sz=ans.size(); while(1){ int w_time=chrono::duration_cast(chrono::system_clock::now()-start_time).count(); if(w_time>lim_time){ break; } int a=0,b=0; while(a==0||a==sz-1) a=randxor()%sz; while(b==0||b==sz-1||b==a) b=randxor()%sz; swap(ans.at(a),ans.at(b)); ll nxcost=Scost_calc(ans); double temp=start_temp+(end_temp-start_temp)*w_time/lim_time; double prob=exp(double(nxcost-nwcost)/temp); if(prob>double(randxor())/double(inf)) nwcost=nxcost; else swap(ans.at(a),ans.at(b)); } const double start_temp2=500; const double end_temp2=0; const int lim_time2=500; while(1){ int w_time=chrono::duration_cast(chrono::system_clock::now()-start_time).count(); w_time-=lim_time; if(w_time>lim_time2){ break; } int a=0,b=0; while(a==0||a==sz-1) a=randxor()%sz; while(b==0||b==sz-1||b==a) b=randxor()%sz; vector> nans; if(a>b) swap(a,b); for(int i=0;i=a;i--) nans.emplace_back(ans.at(i)); for(int i=b;idouble(randxor())/double(inf)) { nwcost=nxcost; ans=nans; } } priority_queue> pq; rep(i,sz-1){ pq.emplace(d.at(ans.at(i).second).at(ans.at(i+1).second),i); } vector mm(m,-1); rep(i,m){ int a=pq.top().second; pq.pop(); mm.at(i)=a; ccd.at(i)=MKsn(v.at(ans.at(a).second),v.at(ans.at(a+1).second)); } vector> nans; int ct=0; rep(i,sz){ nans.emplace_back(ans.at(i)); if(ct