There are n cities in M^3's empire. M^3 owns a palace and a car and the palace resides in city 1. One day, she wants to travel around all the cities from her palace and finally back to her home. However, her car has limited energy and can only travel by no more than D meters. Before it was run out of energy, it should be charged in some oil station. Under M^3's despotic power, the judge is forced to build several oil stations in some of the cities. The judge must build an oil station in city 1 and building other oil stations is up to his choice as long as M^3 can successfully travel around all the cities.
Building an oil station in city i will cost 2 i-1 MMMB. Please help the judge calculate out the minimum cost to build the oil stations in order to fulfill M^3's will.
Building an oil station in city i will cost 2 i-1 MMMB. Please help the judge calculate out the minimum cost to build the oil stations in order to fulfill M^3's will.
Then follows N lines and line i will contain two numbers x, y(0 ≤ x, y ≤ 1000), indicating the coordinate of city i.
The distance between city i and city j will be ceil(sqrt((xi - xj) 2 + (yi - yj) 2)). (ceil means rounding the number up, e.g. ceil(4.1) = 5)
If it's impossible to visit all the cities even after all oil stations are build, output -1 instead.
3 3 0 0 0 3 0 1 3 2 0 0 0 3 0 1 3 1 0 0 0 3 0 1 16 23 30 40 37 52 49 49 52 64 31 62 52 33 42 41 52 41 57 58 62 42 42 57 27 68 43 67 58 48 58 27 37 69
11 111 -1 10111011
/*************************************************************************
> File Name: m3.cpp
> Author:
> Mail:
> Created Time: 2017年11月28日 星期二 10时36分15秒
************************************************************************/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
int n,d;
struct node
{
double x,y;
}p[200];
int bmap[200][200];
int ok[200],vis[200];
int dist[200];
inline double dis(int a,int b)
{
return sqrt((p[a].x-p[b].x)*(p[a].x-p[b].x)+(p[a].y-p[b].y)*(p[a].y-p[b].y));
}
inline bool bfs()
{
for(int i=0;i<n;i++)
{
if(ok[i]) dist[i] = 0;
else dist[i] = 0x3f3f3f3f;
vis[i] = 0;
}
queue<int>q; q.push(0); vis[0] = 1;
while(!q.empty())
{
int u = q.front(); q.pop();
for(int i=0;i<n;i++)
{
if(!vis[i]&&dist[u] + bmap[u][i]<=d)
{
dist[i] = min(dist[i],dist[u] + bmap[u][i]);
if(ok[i])
{
vis[i] = 1;
q.push(i);
}
}
}
}
for(int i=0;i<n;i++)
{
if(ok[i]&&!vis[i]) return false;
if(!ok[i]&&dist[i]*2>d) return false;
}
return true;
}
int main()
{
while(scanf("%d%d",&n,&d)!=EOF)
{
for(int i=0;i<n;i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
}
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
bmap[i][j] = bmap[j][i] = ceil(dis(i,j));
}
}
for(int i=0;i<n;i++) bmap[i][i] = 0;
for(int i=0;i<n;i++) ok[i] = 1;
if(!bfs()){ puts("-1"); continue; }
for(int i=n-1;i>=0;i--)
{
ok[i] = 0;
if(!bfs()) ok[i] = 1;
}
int p = n-1; while(!ok[p]) p--;
for(int i=p;i>=0;i--) printf("%d",ok[i]);
puts("");
}
return 0;
}