Problem:
Problem C:
Dragon Fantasy
永遠に続くと思われていた平和は突然終わりを告げた。 はるか昔に封印されていた魔王がついに復活を遂げたのである。 だが、今まさに世界が闇に覆われようとしているとき、1 人の勇者が現れた。 そしてその勇者は、世界各地に散らばっている伝説のクリスタルを集める旅に出た。 伝説によると、全てのクリスタルを集めることができたならば、どのような願いでもかなえられるという伝説の龍神を呼び出すことができると伝えられている。 その龍神の力を借りれば魔王を倒すことも可能なはずだ。
クリスタルは世界各地に散らばっている。 勇者はそれらを 1 つずつ、自らの手で集めていく必要がある。 なぜなら、勇者以外の者がクリスタルを手に入れたならば、魔王の手先によって奪われてしまうかもしれないからである。 勇者は、1 日あたりユークリッド距離で 1 だけ移動することができる。
しかし、ここで 1 つの重大な問題がある。 魔王は、常に闇の瘴気をまき散らしており、その瘴気に汚染された場所は人が立ち入ることのできない死の大地と化してしまう。 たとえ勇者であってもその場所に立ち入ることはできない。 さらに、その瘴気は時間とともに同心円状に広まっていくため、 時間の経過とともに勇者の移動できる領域は減少していってしまう。 瘴気は 1 日あたりユークリッド距離 1 だけ広がることが確認されている。 そして、その境界線上にあるクリスタルを勇者は取ることはできない。また、復活したばかりの魔王は力を蓄えるために動かないことも分かっている。
勇者は一刻も早くクリスタルを手に入れなければならない。 しかし、もし全てのクリスタルを手に入れることが不可能であるならば、別の手段を考えなければならないだろう。 そこで、あなたには勇者の初期位置と魔王の復活した場所、そしてクリスタルの存在する位置から、全てのクリスタルを手に入れることができるかどうかを調べるプログラムを作っていただきたい。
ちなみに、勇者は疲れない。 そして眠らない。 全てのクリスタルを集めて世界を救うまでは絶えず動き続け、クリスタルを集めるのだ！！
Input
入力は複数のテストケースから構成される。 各テストケースの先頭の行では 5 つの整数
n
(0 <
n
<= 20)、
h
x
、
h
y
、
d
x
、
d
y
が与えられる。
n
はクリスタルの個数、(
h
x
,
h
y
) は魔王が復活した瞬間での勇者の位置、(
d
x
,
d
y
) は魔王が復活した位置である。
			後に続く
n
行には、各クリスタルの位置を表す 2 つの整数
c
x
、
c
y
が与えられる。 入力は
n
=
h
x
=
h
y
=
d
x
=
d
y
= 0 のときに終了し、これはテストケースには含まない。
入力で与えられる全ての座標は絶対値が 1000 以下の整数であることが保証されている。
Output
各テストケースについて、全てのクリスタルを集めることができるならば「YES」と、そうでないならば「NO」と出力せよ。
Sample Input
2 0 0 10 10
1 1
4 4
2 0 0 10 10
1 1
6 6
2 0 0 10 10
1 1
5 5
0 0 0 0 0
Output for the Sample Input
YES
NO
NO

Submitted solutions:

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long double ld;
#define FOR(i,l,r) for(auto i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define F first
#define S second
int main(){
    while(1){
        int N;cin>>N;
        vector<pair<int,int>>C(N+2);
        cin>>C[N].first>>C[N].second;
        cin>>C[N+1].first>>C[N+1].second;
        if(!N)return 0;
        REP(i,N)cin>>C[i].first>>C[i].second;
        auto f=[](pair<int,int>x,pair<int,int>y){
            return sqrt((ld)(x.F-y.F)*(x.F-y.F)+(x.S-y.S)*(x.S-y.S));
        };
        bool ans=0;
        int st=0,cnt=0;
        ld t=0;
        function<void(int)>dfs=[&](int v){
            if(t>=f(C[N+1],C[v]))return;
            if(cnt==N){ans=1;return;}
            REP(i,N)if((st>>i)%2==0&&t+f(C[i],C[v])>=f(C[i],C[N+1]))return;
            REP(i,N)if((st>>i)%2==0){
                cnt++;
                st+=1<<i;
                t+=f(C[v],C[i]);
                dfs(i);
                if(ans)return;
                cnt--;
                st-=1<<i;
                t-=f(C[v],C[i]);
            }
        };
        dfs(N);
        if(ans)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}
accuracy: 1
time_ms: 340
memory_kb: 3312
final_rank: 8

code_snippet: #include<bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
bool dfs(double x2, double y2, vector<pair<double, double>> &c, vector<bool> &used, int id, double d) {
  int n = c.size();
  bool res = false;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (used[i]) {
      cnt++;
    } else {
      double nd = d + hypot(c[i].first - c[id].first, c[i].second - c[id].second);
      double md = hypot(c[i].first - x2, c[i].second - y2);
      if (nd >= md - eps) {
        return false;
      }
    }
  }
  if (cnt == n) return true;
  for (int i = 0; i < n; i++) {
    if (!used[i]) {
      double nd = d + hypot(c[id].first - c[i].first, c[id].second - c[i].second);
      double md = hypot(c[i].first - x2, c[i].second - y2);
      if (nd < md) {
        used[i] = true;
        res |= dfs(x2, y2, c, used, i, nd);
        used[i] = false; 
      }
      if (res) return res;
    }
  }
  return res;
}
int main() {
  while (1) {
    int n, x1, y1, x2, y2;
    cin >> n >> x1 >> y1 >> x2 >> y2;
    if (n == 0 && x1 == 0 && y1 == 0 && x2 == 0 && y2 == 0) {
      break;
    }
    vector<pair<double, double>> c(n);
    for (int i = 0; i < n; i++) {
      cin >> c[i].first >> c[i].second;
    }
    vector<bool> used(n, false);
    bool ans = false;
    for (int i = 0; i < n; i++) {
      double d = hypot(x1 - c[i].first, y1 - c[i].second);
      double md = hypot(x2 - c[i].first, y2 - c[i].second);
      if (d + eps < md) {
        used[i] = true;
        ans |= dfs(x2, y2, c, used, i, d);
        used[i] = false;
      }
      if (ans) break;
    }
    cout << (ans ? "YES" : "NO") << endl;
  }
}
accuracy: 1
time_ms: 610
memory_kb: 3424
final_rank: 15

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
const double pi = 3.141592653589793238462643383279;
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a) * (a))
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

//repetition
//------------------------------------------
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define MOD 1000000007

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const double EPS = 1e-8, PI = acos(-1);
//ここから編集
using Point = complex< double >;
bool eq(double a, double b){ return fabs(a-b) < EPS; }
namespace std {
  bool operator<(const Point a, const Point b) {
    if(eq(a.real(),b.real())) return a.imag() < b.imag();
    return a.real() < b.real();
  }
}

istream &operator>> (istream &is, Point &p) {
  double a, b;
  is >> a >> b;
  p = Point(a, b);
  return is;
}

ostream &operator<< (ostream &os, Point &p) {
  return os << fixed << setprecision(10) << p.real() << " " << p.imag();
}

bool operator<(const Point &a, const Point &b) {
  return a.real() != b.real() ? a.real() < b.real() : a.imag() < b.imag();
}

// rotate Φ(rad)
// x = r * cos(θ + Φ)
//   = r * cos(θ) * cos(Φ) - r * sin(θ) * sin(Φ)
//   = x * cos(Φ) - y * sin(Φ) (∵ cos(θ) = x/r, sin(θ) = y/r)  
Point rotate(double phi, const Point &p) {
  double x = p.real(), y = p.imag();
  return Point(x * cos(phi) - y * sin(phi), x * sin(phi) + y * cos(phi));
}

double radian_to_degree(double r) {
  return (r * 180.0 / PI);
}

double degree_to_radian(double d) {
  return (d * PI / 180.0);
}

struct Line{
  Point a, b;

  Line() = default;

  Line(Point a, Point b) : a(a), b(b){}

  Line(double A, double B, double C){
    //ax + by = c
    if(eq(A, 0)){
      a = Point(0, C/B), b = Point(1, C/B);
    }else if(eq(B, 0)){
      a = Point(C/A, 0), b = Point(C/A, 1);
    }else{
      a = Point(0, C/B), b = Point(C/A, 0);
    }
  }

  friend istream &operator>>(istream &is, Line &a) {
    return is >> a.a >> a.b;
  }
  friend ostream &operator<<(ostream &os, Line &a) {
    return os << a.a << " to " << a.b;
  }
};

struct Segment: Line {
  Segment() = default;

  Segment(Point a, Point b) : Line(a, b) {}
};

struct Circle {
  Point p;
  double r;

  Circle() = default;

  Circle(Point p, double r): p(p), r(r){}
};

using Points = vector<Point>;
using Polygon = vector<Point>;
using Segments = vector<Segment>;
using Lines = vector<Line>;
using Circles = vector<Circle>;

double cross(const Point &a, const Point &b) {
  return a.real() * b.imag() - a.imag() * b.real();
}

double dot(const Point& a, const Point &b) {
  return a.real() * b.real() + a.imag() * b.imag();
}

//https://mathtrain.jp/projection
Point projection(const Line &l, const Point &p){
  double t = dot(p - l.a, l.a-l.b) / norm(l.a - l.b);
  return l.a + (l.a - l.b) * t;
}

Point projection(const Segment &l, const Point &p){
  double t = dot(p - l.a, l.b-l.a) / norm(l.a - l.b);
  return l.a + (l.b - l.a) * t;
}

Point reflection(const Line &l, const Point &p){
  return p + (projection(l, p) - p) * 2.0;
}

int ccw(const Point &a, const Point &b, const Point &c) {
  if(cross(b-a, c-a) > EPS) return 1;   // "COUNTER_CLOCKWISE"
  if(cross(b-a, c-a) < -EPS) return -1; // "CLOCKWISE"
  if(dot(b-a, c-a) < -EPS) return 2;    // "ONLINE_BACK" c-a-b
  if(norm(b-a) < norm(c-a) - EPS) return -2;  // "ONLINE_FRONT" a-b-c
  return 0;                         // "ON_SEGMENT" a-c-b
}

bool parallel(const Line &a, const Line &b){
  return eq(cross(a.a-a.b, b.a-b.b), 0.0);
}
bool orthogonal(const Line &a, const Line &b){
  return eq(dot(a.a-a.b, b.a-b.b), 0.0);
}
enum { OUT, ON, IN };

int contains(const Polygon& Q, const Point& p){
  bool in = false;
  for(int i=0; i<Q.size(); i++){
    Point a = Q[i] - p, b = Q[(i+1)%Q.size()]-p;
    if(a.imag() > b.imag()) swap(a, b);
    if(a.imag() <= 0 && 0 < b.imag() && cross(a, b) < 0) in = !in;
    if(cross(a, b) == 0 && dot(a, b) <= 0) return ON;
  }
  return in ? IN : OUT;
}
bool intersect(const Segment &s, const Point &p){
  return ccw(s.a, s.b, p) == 0;
}

//直線の交差判定
bool intersect(const Line &a, const Line &b) {
  if(parallel(a, b)) return 0;
  return 1;
}

//線分が重なる/端点で交わるときtrue
bool intersect(const Segment &a, const Segment &b) {
  return ccw(a.a, a.b, b.a) * ccw(a.a, a.b, b.b) <= 0 && ccw(b.a, b.b, a.a) * ccw(b.a, b.b, a.b) <= 0;
}

bool intersect(const Line &l, const Segment &s) {
  
}

Point crosspoint(const Line &a, const Line &b){
  double d = cross(b.b-b.a, a.b-a.a);
  if(eq(d, 0.0)) return Point(1e9, 1e9); 
  
  return a.a + (a.b - a.a) * cross(b.b-b.a, b.b-a.a) / d;
}

Point crosspoint(const Segment &a, const Segment &b){
  return crosspoint(Line(a.a, a.b), Line(b.a, b.b));
}
double distance(const Point &a, const Point &b){
  return abs(a - b);
}
double distance(const Line &l, const Point &p){
  return abs( cross(p - l.a, l.b-l.a) / abs(l.b-l.a) );
}
double distance(const Segment &s, const Point &p){
  Point r = projection(s, p);
  if(intersect(s, r)) return abs(r-p);
  return min(abs(s.a - p), abs(s.b - p));
}
// double distance(const Line &a, const Line &b){

// }
// double distance(const Line &a, const Segment &b){

// }
double distance(const Segment &a, const Segment &b) {
  return intersect(a, b) ? 0 : min({distance(a, b.a), distance(a, b.b), distance(b, a.a), distance(b, a.b)});
}

/* 2円の交点 */
vector<Point> crosspointCC(Circle C1, Circle C2){
  vector<Point> ps;
  Point ab = C2.p - C1.p;
  double d = abs(ab);
  double rc = (C1.r * C1.r + d * d - C2.r * C2.r) / (2 * d);
  if(eq(d, 0) || C1.r < abs(rc)) return ps;

  double rs = sqrt(C1.r * C1.r - rc*rc);

  Point abN = ab * Point(0, rs/d);
  Point cp = C1.p + rc / d * ab;
  ps.push_back(cp + abN);
  if(!eq(norm(abN), 0))ps.push_back(cp-abN);
  return ps;
}

vector<Point> crosspointCL(Circle C, Line l){
  Point p = projection(l, C.p);

  Point e = (l.b-l.a)/abs(l.b-l.a);
  if(eq(distance(l, C.p), C.r)) {
    return vector<Point>{p, p};
  }
  double base = sqrt(C.r*C.r-norm(p-C.p));
  
  return vector<Point>{p+e*base, p-e*base};
}

/* 円同士の共通部分の面積を求める */
// verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_I date: 2020/10/11
long double AreaofCC(Circle& C1, Circle& C2){
  if(C1.r > C2.r) swap(C1, C2);
  long double nor = norm(C1.p - C2.p);
  long double dist = sqrtl(nor);
  
  if(C1.r + C2.r < dist+EPS) return 0;

  if(dist + C1.r < C2.r + EPS) return C1.r * C1.r * PI;

  long double theta1 = acosl((nor + C1.r*C1.r - C2.r * C2.r)/(2*C1.r*dist));

  long double theta2 = acosl((nor + C2.r*C2.r - C1.r * C1.r)/(2*C2.r*dist));
  
  return (theta1 - sinl(theta1+ theta1) *0.5) * C1.r * C1.r + (theta2 - sinl(theta2+theta2) *0.5) * C2.r * C2.r;
}


Polygon convex_hull(Polygon &p)
{
    int n = (int)p.size(), k = 0;
    if (n <= 2)
        return p;
    sort(p.begin(), p.end());
    vector<Point> ch(n * 2);

    for (int i = 0; i < n; ch[k++] = p[i++])
    {
        while (k >= 2 && cross(ch[k - 1] - ch[k - 2], p[i] - ch[k - 1]) < 0)
            --k;
    }

    for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = p[i--])
    {
        while (k >= t && cross(ch[k - 1] - ch[k - 2], p[i] - ch[k - 1]) < 0)
            --k;
    }
    ch.resize(k - 1);
    return ch;
}

double closestpair(Points &a, int l, int r){
  if(r-l<=1) return 1e20;
  int mid = (l+r)/2;

  double X = a[mid].real();
  double d = min(closestpair(a, l, mid), closestpair(a, mid, r));
  inplace_merge(a.begin()+l, a.begin()+mid, a.begin()+r, [](const Point& pa, const Point& pb){
    return pa.imag() < pb.imag();
  });

  Points b;
  for(int i=l; i<r; i++){
    if(abs(a[i].real()-X) >= d) continue;
    for(int j=b.size()-1; j>=0; j--){
      if(abs((a[i]-b[j]).imag()) >= d) break;
      d = min(d, abs(a[i]-b[j]));
    }
    b.push_back(a[i]);
  }
  return d;
}

/* 円の交差判定 */
/* verify: http://judge.u-aizu.ac.jp/onlinejudge/finder.jsp?course=CGL date:2020/10/11 */
int intersectionCC(Circle c1, Circle c2){
  if(c1.r > c2.r) swap(c1, c2);
  double d1 = abs(c1.p-c2.p); 
  double d2 = c1.r + c2.r;
  if(d1 > d2) return 4; /* 互いに交点を持たない */
  else if(d1 == d2) return 3; /* 外接する場合 */
  else{
    if(c2.r == c1.r + d1) return 1; /* 内接する場合 */
    else if(c2.r > c1.r + d1) return 0; /* 包含 */
    else return 2; /* 交点を2つ持つ */
  }
}

/* 点集合が反時計回りに与えられる場合のみ */
double Area(Points &g){
  double res = 0;
  int n = g.size();
  REP(i,n){
    res += cross(g[i], g[(i+1)%n]);
  }
  return res/2.0;
}

/* 内接円 */
/* verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_B&lang=ja date: 2020/10/11 */
pair<Point, double> incircle_of_a_Triangle(Points &p){

  double a = abs(p[1]-p[2]), b = abs(p[2]-p[0]), c = abs(p[0]-p[1]);
  double s = (a+b+c) / 2.0;
  double S = sqrtl(s*(s-a)*(s-b)*(s-c));
  double r = S/s; 
  
  Point pp = (a*p[0]+b*p[1]+c*p[2])/(a+b+c);
  return make_pair(pp, r);
} 

/* 外接円 */
pair<Point, double> circumscribed_circle_of_a_triangle(Points &p){

  Point m1((p[0]+p[1])/2.0), m2((p[1]+p[2])/2.0);
  Point v((p[1]-p[0]).imag(), (p[0]-p[1]).real()), w((p[1]-p[2]).imag(), (p[2]-p[1]).real());

  Line l1(m1, Point(v+m1)), l2(m2, Point(w+m2));

  Point x = crosspoint(l1, l2);
  double r = abs(x-p[0]);
  return make_pair(x, r);
}

/* ある点pを通る円cの接線 */
Points tangent_to_a_circle(Point p, Circle C){
  Points ps;
  double d = abs(C.p-p);
  if(eq(d,0)){
    ps.push_back(p);
  }else if(d>EPS){
    
    double d2 = sqrt(d*d-C.r*C.r);
    
    long double theta = acosl(d2/d);
    //cout << theta << endl;
    Point pp = C.p - p;
    Point p2 = rotate(-theta, pp);

    Point e = p2/abs(p2);
    Point ppp = e*d2;
    ps.push_back(p + ppp);
    p2 = rotate(theta, pp);
    e = p2/abs(p2);
    ppp = e*d2;
    ps.push_back(p + ppp);
    
  }
  return ps;
}

Lines tangent(Circle C1, Circle C2){
  Lines ls;
  if(C1.r < C2.r) swap(C1, C2);
  double d = norm(C1.p - C2.p);
  if(eq(d, 0)) return ls;
  Point u = (C2.p - C1.p) / sqrt(d);
  Point v = rotate(pi/2, u);

  for(double s: {-1, 1}) {
    double h = (C1.r + s * C2.r) / sqrt(d);
    if(eq(1-h*h, 0)) {
      ls.emplace_back(C1.p + u * C1.r, C1.p + (u+v) * C1.r);
    }else if(1-h*h>0){
      Point uu = u*h, vv = v*sqrt(1-h*h);
      ls.emplace_back(C1.p + (uu+vv) * C1.r, C2.p - (uu+vv) * C2.r * s);
      ls.emplace_back(C1.p + (uu-vv) * C1.r, C2.p - (uu-vv) * C2.r * s);
    }
  }
  return ls;
}

using ld = long double;
ld dist(ld sx, ld sy, ld tx, ld ty){
    return sqrtl((sx-tx)*(sx-tx) + (sy-ty)*(sy-ty));
}
int n;
ld hx, hy, dx, dy;
vector<double> cx(25), cy(25);
bool dfs(ld x, ld y, ld t, int bit){
    
    if(bit == (1<<n)-1){
        return true;
    }
    
    REP(i,n){
        if(bit >> i & 1) continue;
        if(t + dist(x, y, cx[i], cy[i]) + EPS > dist(dx, dy, cx[i], cy[i])) return false;
    }

    for(int i=0; i<n; i++){
        if(bit >> i & 1) continue;

        ld d = dist(x, y, cx[i], cy[i]);
        ld mao = dist(dx, dy, cx[i], cy[i]);
        if(d+t + EPS > mao) return false;
        if(dfs(cx[i], cy[i], t+d, bit | (1 << i))) return true;
    }
    return false;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(6);
    
    
    while(cin >> n >> hx >> hy >> dx >> dy){
        if(n==0&&hx==0&&hy==0&&dx==0&&dy==0) break;
        REP(i,n){
            cin >> cx[i] >> cy[i];
        }
        
        if(dfs(hx, hy, 0.0, 0)) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 380
memory_kb: 3288
final_rank: 11

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
const double EPS = 1e-8;
int n;
int x[22],y[22];
double di[22][22];
double dist(double sx, double sy, double gx, double gy){
    return sqrt((gx-sx)*(gx-sx) +(gy-sy)*(gy-sy));
}
bool used[21];
bool dfs(int c, double d, int m){
    if(n == m) return true;
    for(int i=1; i<n; i++){
        if(used[i]) continue;
        if(d +di[c][i] +EPS > di[i][n]){
            return false;
        }
    }
    for(int i=1; i<n; i++){
        if(used[i]) continue;
        used[i] = true;
        if(dfs(i, d+di[c][i], m+1)){
            return true;
        }
        used[i] = false;
    }
    return false;
}

int main(){
    while(1){
        int sx,sy,dx,dy;
        cin >> n >> sx >> sy >> dx >> dy;
        if(n == 0) break;

        x[0] = sx;
        y[0] = sy;
        for(int i=0; i<n; i++){
            cin >> x[i+1] >> y[i+1];
        }
        n++;
        x[n] = dx;
        y[n] = dy;
        for(int i=1; i<n; i++){
            used[i] = false;
        }
        for(int i=0; i<n+1; i++){
            for(int j=0; j<n+1; j++){
                di[i][j] = di[j][i] = dist(x[i],y[i],x[j],y[j]);
            }
        }
        if(dfs(0, 0, 1)){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    return 0;
}
accuracy: 1
time_ms: 130
memory_kb: 3112
final_rank: 5

code_snippet: #include "bits/stdc++.h"

using namespace std;

int N,M,K,L,R,H,W;

const long long int MOD=1000000007;
const float EPS=1e-8;

float dis(float a,float c,float b,float d){
	return sqrt((a-b)*(a-b)+(c-d)*(c-d));
}

float dp[1<<20][20];

int main(){

	int N;
	float sx,sy,gx,gy;
	while(cin>>N>>sx>>sy>>gx>>gy,N){
		vector<float>y(N);
		vector<float>x(N);
		vector<float>devil(N);
		bool f = true;
		for(int i=0;i<N;i++){
			cin>>x[i]>>y[i];
			devil[i]=dis(gx,gy,x[i],y[i]);
			if (devil[i] < dis(sx,sy,x[i],y[i])) {
				f = false;
			}
		}
		if (!f) {
			cout << "NO\n";
			continue;
		}
		vector<vector<float>>dist(N,vector<float>(N));
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++){
				dist[i][j]=dis(x[i],y[i],x[j],y[j]);
			}
		}
		for(int i=0;i<1<<N;i++){
			for(int j=0;j<N;j++){
				dp[i][j]=MOD;
			}
		}
		for(int i=0;i<N;i++){
			if(devil[i]-EPS>dis(sx,sy,x[i],y[i])){
				dp[1<<i][i]=dis(sx,sy,x[i],y[i]);
			}
		}
		for(int i=1;i<1<<N;i++){
			for(int j=0;j<N;j++){
				if(!((i>>j)&1))continue;
				if(dp[i][j]>=1000000)continue;
				bool hoge = false;
				for(int k=0;k<N;k++){
					if((i>>k)&1)continue;
					if(dp[i][j]+dist[j][k] > devil[k] + EPS)hoge = true;
				}

				if(hoge)continue;
				for(int k=0;k<N;k++){
					if((i>>k)&1)continue;
					float nx=dp[i][j]+dist[j][k];
					if(nx<devil[k]-EPS){
						dp[i|(1<<k)][k]=min(dp[i|(1<<k)][k],nx);
					}
				}
			}
		}

		float ans=MOD;
		for(int i=0;i<N;i++){
			ans=min(ans,dp[(1<<N)-1][i]);
		}
		if(ans>=10000000){
			cout<<"NO\n";
		}
		else{
			cout<<"YES\n";
		}
	}

	return 0;
}
accuracy: 1
time_ms: 6630
memory_kb: 85184
final_rank: 20

code_snippet: #include <string>
#include <vector>
#include <iostream>
#include <queue>
#include <functional>
#include <algorithm>
#include <random>
#include <cmath>
#include <climits>
#include <iomanip>
#include <cfloat>
#include <set>
#include <map>
#include <tuple>
struct Point {
	float x, y;
	float distance(const Point &that) const {
		return std::sqrt((x - that.x) * (x - that.x) + (y - that.y) * (y - that.y));
	}
};

void solve() {
	int n;
	float hx, hy, dx, dy; std::cin >> n >> hx >> hy >> dx >> dy;
	std::vector<std::vector<float>> memo(20, std::vector<float>(1 << 20, FLT_MAX));
	while (n != 0) {
		auto is_end = false;
		Point start{ hx, hy }, mao{ dx, dy };
		for (auto &m : memo)std::fill(m.begin(), m.end(), FLT_MAX);
		std::vector<Point> crystal(n); for (auto &c : crystal) std::cin >> c.x >> c.y;
		std::priority_queue<std::tuple<int, int, int>, std::vector<std::tuple<int, int, int>>, std::function<bool(const std::tuple<int, int, int> &, const std::tuple<int, int, int> &)>> queue([n, &memo](const std::tuple<int, int, int> &a, const std::tuple<int, int, int> &b) {return (std::get<2>(a) == std::get<2>(b)) ? memo[std::get<0>(a)][std::get<1>(a)] > memo[std::get<0>(b)][std::get<1>(b)] : std::get<2>(a) < std::get<2>(b); });
		for (auto i = 0; i < n && !is_end; ++i) {
			if (start.distance(crystal[i]) < mao.distance(crystal[i])) {
				memo[i][1 << i] = start.distance(crystal[i]);
				queue.push(std::make_tuple(i, 1 << i, 1));
			}
			else {
				std::cout << "NO\n";
				is_end = true;
			}
		}
		bool can = true;
		while (!queue.empty() && !is_end) {
			auto current = std::get<0>(queue.top());
			auto flag = std::get<1>(queue.top());
			auto count = std::get<2>(queue.top());
			auto distance = memo[current][flag];
			queue.pop();
				can = true;
				for (auto i = 0; i < n && can; ++i) {
					if ((flag & (1 << i)) == 0 && distance + crystal[current].distance(crystal[i]) >= mao.distance(crystal[i])) {
						can = false;
					}
				}
				if (can) for (auto i = 0; i < n && !is_end; ++i) {
					if ((flag & (1 << i)) == 0) {
						if (memo[i][flag | (1 << i)] > distance + crystal[current].distance(crystal[i])) {
							if (count + 1 == n) {
								std::cout << "YES\n";
								is_end = true;
							}
							memo[i][flag | (1 << i)] = distance + crystal[current].distance(crystal[i]);
							queue.push(std::make_tuple(i, flag | (1 << i), count + 1));
						}
					}
				}
		}
		if (!is_end) {
			if (std::any_of(memo.begin(), memo.end(), [n](const std::vector<float> &v) {return v[(1 << n) - 1] != FLT_MAX; })) {
				std::cout << "YES\n";
			}
			else {
				std::cout << "NO\n";
			}
		}
		std::cin >> n >> hx >> hy >> dx >> dy;
	}
}
int main() {
	solve();
}
accuracy: 1
time_ms: 2310
memory_kb: 88900
final_rank: 19

code_snippet: #include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int n;
int x[20],y[20];
int sx,sy,mx,my;
bool c[20];
bool f(int u,double d)
{
	int cnt=0;
	for(int i=0;i<n;i++)
	{
		if(c[i])
		{
			cnt++;
			continue;
		}
		double a=hypot(x[u]-x[i],y[u]-y[i])+d;
		double b=hypot(mx-x[i],my-y[i]);
		if(b<=a)return false;
	}
	if(cnt==n)return true;
	for(int i=0;i<n;i++)
	{
		if(c[i])continue;
		double a=hypot(x[u]-x[i],y[u]-y[i])+d;
		double b=hypot(mx-x[i],my-y[i]);
		if(b>a)
		{
			c[i]=1;
			if(f(i,a))return true;
			c[i]=0;
		}
	}
	return false;
}
main()
{
	while(cin>>n>>sx>>sy>>mx>>my,n)
	{
		for(int i=0;i<n;i++)cin>>x[i]>>y[i];
		for(int i=0;i<n;i++)c[i]=0;
		bool fl=0;
		for(int i=0;!fl&&i<n;i++)
		{
			double a=hypot(sx-x[i],sy-y[i]);
			double b=hypot(mx-x[i],my-y[i]);
			if(a<b)
			{
				c[i]=1;
				fl|=f(i,a);
				c[i]=0;
			}
			else break;
		}
		cout<<(fl?"YES":"NO")<<endl;
	}
}
accuracy: 1
time_ms: 630
memory_kb: 2996
final_rank: 14

code_snippet: #include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
double eps=1e-9;
int x[23];
int y[23];
double dist[23][23];
int n;
int solve(int a,int b,double s){
    if(a==(1<<n)-1)return 1;
    for(int i=0;i<n;i++){//枝切り
        if(a&(1<<i))continue;
        if(s+dist[b][i]+eps>dist[n+1][i])return 0;
    }
    for(int i=0;i<n;i++){
        if(a&(1<<i))continue;
        
        if(solve(a+(1<<i),i,s+dist[b][i]))return 1;
    }
    return 0;
}
int main(){
    int a,hx,hy,dx,dy;
    while(scanf("%d%d%d%d%d",&a,&hx,&hy,&dx,&dy),a){
        n=a;
        for(int i=0;i<a;i++)scanf("%d%d",x+i,y+i);
        x[a]=hx;x[a+1]=dx;
        y[a]=hy;y[a+1]=dy;
        for(int i=0;i<a+2;i++)for(int j=0;j<a+2;j++)
            dist[i][j]=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
        if(solve(0,a,0))printf("YES\n");
        else printf("NO\n");
    }
}
accuracy: 1
time_ms: 140
memory_kb: 2572
final_rank: 4

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

struct Info{
	int x,y;
};

int N,POW[21];
Info start,enemy,info[21];
double dist_table[21][21],poison_TIME[20];
bool FLG;

double calc_Time(Info from,Info to){
	return sqrt((from.x-to.x)*(from.x-to.x)+(from.y-to.y)*(from.y-to.y));
}

void dfs(int node_id,int count,double total_time,int state){

	if(count == N){
		FLG = true;
	}
	if(FLG)return;

	for(int i = 0; i < N; i++){
		if(state & (1 << i)){
			//Do nothing
		}else{
			double next_time = total_time+dist_table[node_id][i];
			if(next_time >= poison_TIME[i])return;
		}
	}

	for(int i = 0; i < N; i++){
		if(state & (1 << i)){
			//Do nothing
		}else{
			double next_time = total_time+dist_table[node_id][i];
			int next_state = state + POW[i];
			dfs(i,count+1,next_time,next_state);
		}
	}
}

void func(){

	for(int i = 0; i < N; i++){
		scanf("%d %d",&info[i].x,&info[i].y);
		poison_TIME[i] = calc_Time(info[i],enemy);
	}
	info[N].x = start.x;
	info[N].y = start.y;

	double tmp;
	for(int i = 0; i < N; i++){
		for(int k = i+1; k <= N; k++){
			tmp = calc_Time(info[i],info[k]);
			dist_table[i][k] = tmp;
			dist_table[k][i] = tmp;
		}
	}

	FLG = false;

	dfs(N,0,0,0);

	if(FLG){
		printf("YES\n");
	}else{
		printf("NO\n");
	}
}

int main(void){

	for(int i = 0; i <= 20; i++)POW[i] = pow(2,i);

    while(true){
    	scanf("%d %d %d %d %d",&N,&start.x,&start.y,&enemy.x,&enemy.y);

    	if(N == 0)break;

    	func();
    }
    return 0;
}
accuracy: 1
time_ms: 120
memory_kb: 3284
final_rank: 6

code_snippet: #include<iostream>
#include<cmath>
#include<string>

using namespace std;

#define REP(i,n) for(int i = 0;i < n ;i++)
#define EPS 1e-8

int n,hx,hy,dx,dy;
int x[30],y[30];

bool flag;

void dfs(int unvisit,int cx,int cy,double t)
{
	if(flag) return;
	if(unvisit == 0)flag = true;
	
	else
	{
		REP(i,n)
		{
			if(!((unvisit >> i) & 1))continue;
			if(hypot(dx-x[i],dy-y[i]) <= t + hypot(cx-x[i],cy-y[i]))return;
		}
		
		REP(i,n)
		{
			if(!((unvisit >> i) & 1))continue;
			dfs((unvisit & ~(1 << i)),x[i],y[i],t + hypot(cx-x[i],cy-y[i]));
		}
	}
}

string solve()
{
	flag = false;
	dfs((1<<n)-1,hx,hy,0);
	return (flag)?"YES":"NO";
}

int main()
{
	while(cin >> n >> hx >> hy >> dx >> dy,n)
	{
		REP(i,n)
		{
			cin >> x[i] >> y[i];
		}
		
		cout << solve() << endl;
		
	}
	
	return 0;
	
}
accuracy: 1
time_ms: 520
memory_kb: 3000
final_rank: 13

code_snippet: #include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
inline double dist(int x, int y) {
	return std::sqrt(x * x + y * y);
}
inline double dist(std::pair<int, int> pos) {
	return std::sqrt(pos.first * pos.first + pos.second * pos.second);
}
inline double dist(int x, int y, std::pair<int, int> pos) {
	return std::sqrt((x - pos.first) * (x - pos.first) + (y - pos.second) * (y - pos.second));
}

std::vector<std::pair<int, int>> crystal;
int n, x, y, mx, my;
bool Solve(double day = 0, std::vector<std::pair<int, int>> got = {});
bool isClear = false;
int main()
{
	std::vector<std::string> results;
	while (1) {
		std::cin >> n >> x >> y >> mx >> my;
		if (!x && !y && !n && !mx && !my) break;
		crystal.clear();
		for (int i = 0; i < n; i++) {
			int cx, cy;
			std::cin >> cx >> cy;
			cx -= mx; cy -= my;
			crystal.push_back(std::make_pair(cx, cy));
		}
		x -= mx; y -= my;
		mx = 0; my = 0;
		isClear = false;
		Solve();
		results.push_back(isClear ? "YES" : "NO");
	}

	for (auto& x : results) {
		std::cout << x << std::endl;
	}

	return 0;
}

bool Solve(double day, std::vector<std::pair<int, int>> got)
{
	if (isClear) return true;
	bool ok = false;
	int posX, posY;
	if (got.empty()) {
		posX = x;
		posY = y;
	}
	else {
		posX = got.back().first;
		posY = got.back().second;
	}
	//??¨??£??????????????´?????¨??????????????????????????£?????????
	for (auto& x : crystal) {
		//???????????????????¨????(?????¢???????????????????????????)
		double pass = dist(posX, posY, x);
		double next = day + pass;
		//?????£?????????crystal?????????????????????????????????????????????
		if (next < dist(x)) {
			//??´?°????????????¨??????????¨????
			if (std::find(got.begin(), got.end(), x) == got.end()) {
				got.push_back(x);
				if (got.size() == n) {
					isClear = true;
				}
				ok = ok | Solve(next, got);
			}
		}
	}
	return ok;
}
accuracy: 1
time_ms: 2750
memory_kb: 3104
final_rank: 17

code_snippet: #include <bits/stdc++.h>
  
using namespace std;
  
#define MAX 21
#define EPS 1e-9
#define INF 1e9
 
struct Point{
    double x, y;
}; 
 
int N;
Point h, d, crystal[MAX];
  
double dist(Point a, Point b){
    return sqrt(pow(a.x-b.x,2) + pow(a.y-b.y,2));
}
 
bool rec(int S, int v, double total_dist){
    if(S == (1 << N) - 1){
	return true;
    }
    for(int u = 0 ; u < N ; u++){
	if(!(S >> u & 1)){
	    if(total_dist + dist(crystal[v],crystal[u]) >= dist(d, crystal[u])){
		return false;
	    }
	}
    }
    for(int u = 0 ; u < N ; u++){
	if(!(S >> u & 1)){
	    if(rec(S | 1 << u, u, total_dist + dist(crystal[v],crystal[u]))){
		return true;
	    }
	}
    }
}
 
bool solve(){
    for(int i = 0 ; i < N ; i++){
	if(rec(0,i,dist(h,crystal[i]))){
	    return true;
	}
    }  
    return false;
}
  
int main(){
    while(cin >> N >> h.x >> h.y >> d.x >> d.y, (N + h.x + h.y + d.x + d.y)){
	for(int i = 0 ; i < N ; i++){
	    cin >> crystal[i].x >> crystal[i].y;
	}
	cout << (solve() ? "YES" : "NO") << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 500
memory_kb: 3160
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;

int n;
vector<int> x, y;
vector<int> viewed;

double dist(int a, int b){
    return sqrt((x[a]-x[b])*(x[a]-x[b]) + (y[a]-y[b])*(y[a]-y[b]));
}

bool dfs(int v, double t, int c){
    if(c == n) return true;

    for(int i=0;i<n;i++){
        if(viewed[i]) continue;
        if(t + dist(v, i) >= dist(i, n+1)) return false;
    }

    for(int i=0;i<n;i++){
        if(viewed[i]) continue;
        double nt = t + dist(v, i);
        if(nt < dist(i, n+1)){
            viewed[i] = true;
            if(dfs(i, nt, c+1)) return true;
            viewed[i] = false;
        }
    }

    return false;
}

int main(){
    while(1){
        cin >> n;
        if(n == 0) break;
        x.assign(n+2, 0);
        y.assign(n+2, 0);
        cin >> x[n] >> y[n] >> x[n+1] >> y[n+1];
        for(int i=0;i<n;i++){
            cin >> x[i] >> y[i];
        }
        viewed.assign(n, 0);
        if(dfs(n, 0, 0)){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    return 0;
}
accuracy: 1
time_ms: 460
memory_kb: 1188
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;

int n;
vector<int> x, y;
vector<bool> viewed;

double dist(int a, int b){
    return sqrt((x[a]-x[b])*(x[a]-x[b]) + (y[a]-y[b])*(y[a]-y[b]));
}

bool dfs(int v, double t, int c){
    if(c == n) return true;

    for(int i=0;i<n;i++){
        if(viewed[i]) continue;
        if(t + dist(v, i) >= dist(i, n+1)) return false;
    }

    for(int i=0;i<n;i++){
        if(viewed[i]) continue;
        double nt = t + dist(v, i);
        if(nt < dist(i, n+1)){
            viewed[i] = true;
            if(dfs(i, nt, c+1)) return true;
            viewed[i] = false;
        }
    }

    return false;
}

int main(){
    while(1){
        cin >> n;
        if(n == 0) break;
        x.assign(n+2, 0);
        y.assign(n+2, 0);
        cin >> x[n] >> y[n] >> x[n+1] >> y[n+1];
        for(int i=0;i<n;i++){
            cin >> x[i] >> y[i];
        }
        viewed.assign(n, false);
        if(dfs(n, 0, 0)){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    return 0;
}
accuracy: 1
time_ms: 370
memory_kb: 3080
final_rank: 9

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>

#define EPS	1.0e-10
#define MAX_CRYSTAL	32
#define rep(idx, max)	for(int idx = 0, idx##Max = max; idx < idx##Max; idx ++)

typedef struct _POINT
{
	int x, y;

	_POINT() {}
	_POINT(int _x, int _y) : x(_x), y(_y) {}
} POINT;

int g_crystalNum;
POINT	g_hero, g_devil;
POINT	g_crystals[MAX_CRYSTAL];

int	g_bSolved;
int	g_bReached[MAX_CRYSTAL];
int	g_reachedCount;

double Distance(const POINT &src1, const POINT &src2)
{
	double x = src1.x - src2.x;
	double y = src1.y - src2.y;
	return( ::sqrt(x * x + y * y) );
}

void Solve(const POINT &pt, const double time)
{
	//std::cout << time << std::endl;
	if (g_bSolved) { return; }

	if (g_reachedCount == g_crystalNum)
	{
		g_bSolved = true;
		return;
	}

	rep(n, g_crystalNum)
	{
		if (g_bReached[n]) { continue; }
		double r = time + ::Distance(pt, g_crystals[n]);	// Elapsed time of hero
//		if (r - ::Distance(g_devil, g_crystals[n]) > EPS) { return; }	// Could not reached (You are too late :P)
		if (::Distance(g_devil, g_crystals[n]) < r + EPS) { return; }	// Could not reached (You are too late :P)
	}

	rep(n, g_crystalNum)
	{
		if (g_bReached[n]) { continue; }

		g_bReached[n] = true;
		g_reachedCount++;
		::Solve(g_crystals[n], time + ::Distance(pt, g_crystals[n]));
		g_bReached[n] = false;
		g_reachedCount--;
	}
}

int main(int nArgs, char **lplpszArgs)
{
	while (std::cin >> g_crystalNum)
	{
		std::cin >> g_hero.x >> g_hero.y >> g_devil.x >> g_devil.y;
		if (g_crystalNum == 0) { break; }
		rep(i, g_crystalNum)
		{
			POINT &pt = g_crystals[i];
			std::cin >> pt.x >> pt.y;
		}

		//::printf("Hero: (%d, %d), Devil: (%d, %d)\n", g_hero.x, g_hero.y, g_devil.x, g_devil.y);

		g_bSolved = false;
		::memset(g_bReached, 0, sizeof(g_bReached));
		g_reachedCount = 0;
		::Solve(g_hero, 0);
		std::cout << (g_bSolved ? "YES" : "NO") << std::endl;
	}
}
accuracy: 1
time_ms: 520
memory_kb: 1152
final_rank: 10

code_snippet: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
vi x,y;
int n,a,b,c,d;
bool f(int q,int nx,int ny,double t){
	if(q==(1<<n)-1)return 1;
	rep(i,n)if((q&1<<i)==0&&(hypot(nx-x[i],ny-y[i])+t+EPS>hypot(c-x[i],d-y[i])))return 0;
	rep(i,n)if((q&1<<i)==0&&f(q^1<<i,x[i],y[i],t+hypot(nx-x[i],ny-y[i])))return 1;
	return 0;
}
int main(){
	while(cin>>n,n){
		cin>>a>>b>>c>>d;
		y=x=vi(n);
		rep(i,n)cin>>x[i]>>y[i];
		cout<<(f(0,a,b,0)?"YES":"NO")<<endl;
	}
	cin>>n>>n>>n>>n;
}
accuracy: 1
time_ms: 970
memory_kb: 1220
final_rank: 16

code_snippet: #include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int n,hx,hy,dx,dy;

float dist[21][21];
struct Crystal{
    int x,y;
    float dist;
    bool visited;
};
Crystal crystals[21];//[0]????????????????????????????????????

bool rec(int s,float t){
    crystals[s].visited=true;
    bool b=true;
    for(int i=1;i<=n;i++){
        if(crystals[i].visited) continue;
        if(dist[i][s]+t<crystals[i].dist){
            if(rec(i,dist[i][s]+t)){
                //cout << s << ",";
                return true;
            }else{
                b=false;
            }
        }else{
            //???????????????????????????????????£??????
            crystals[s].visited=false;
            return false;
        }
    }
    //??¨???????????????????????????????????????
    //cout << s << ",";
    crystals[s].visited=false;
    return b;
}

int main(void){
    while(cin >> n >> crystals[0].x >> crystals[0].y >> dx >> dy,n){
        for(int i=1;i<=n;i++){
            cin >> crystals[i].x >> crystals[i].y;
            crystals[i].dist=sqrt(pow(crystals[i].x-dx,2)+pow(crystals[i].y-dy,2));
        }
        sort(crystals+1,crystals+n+1,[](const Crystal& a, const Crystal& b){return (a.dist==b.dist)?(a.x<b.x):(a.dist)<(b.dist);});
        for(int i=0;i<=n;i++){
            crystals[i].visited=false;
            for(int k=i+1;k<=n;k++){
                dist[i][k]=dist[k][i]=sqrt(pow(crystals[i].x-crystals[k].x,2)+pow(crystals[i].y-crystals[k].y,2));
            }
        }
        if(rec(0,0)){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 3084
final_rank: 3

code_snippet: #include <cstdio>
#include <cmath>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

int n;
double x[22];
double y[22];
double d[22][22];

bool dfs(int k, int x, double c){
	if(x == (1 << n) - 1){
		return true;
	}
	rep(i, n){
		if(
			!(x & (1 << i)) &&
			c + d[k][i] >= d[i][n + 1]
		){
			return false;
		}
	}
	rep(i, n){
		if(
			!(x & (1 << i)) &&
			dfs(i, x | (1 << i), c + d[k][i])
		){
			return true;
		}
	}
	return false;
}

int main(){
	while(1){
		scanf("%d", &n);
		if(n == 0){
			break;
		}
		scanf("%lf%lf%lf%lf", x + n, y + n,  x + n + 1, y + n + 1);
		rep(i, n){
			scanf("%lf%lf", x + i, y + i);
		}
		rep(i, n + 2){
			rep(j, n + 2){
				double dx = x[i] - x[j];
				double dy = y[i] - y[j];
				d[i][j] = sqrt(dx * dx + dy * dy);
			}
		}
		printf("%s\n", dfs(n, 0, 0) ? "YES" : "NO");
	}
	return 0;
}
accuracy: 1
time_ms: 150
memory_kb: 1052
final_rank: 1

code_snippet: #include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <functional>

using namespace std;

typedef pair<int, int> P;
typedef pair<double, int> R;
typedef pair<P, R> Q;

int main() {
	int n, hx, hy, dx, dy;
	double r;
	while (cin >> n >> hx >> hy >> dx >> dy) {
		if (n == 0 && hx == 0 && hy == 0 && dx == 0 && dy == 0) {
			break;
		}
		hx -= dx;
		hy -= dy;
		vector<P> data;
		int x, y;
		for (int i = 0; i < n; i++) {
			cin >> x >> y;
			x -= dx;
			y -= dy;
			data.push_back(P(x, y));
		}
		vector< vector<double> > data2(n, vector<double>(n));
		for (int i = 0; i < n; i++) {
			for (int j = i+1; j < n; j++) {
				data2[i][j] = data2[j][i] = sqrt(pow(data[i].first-data[j].first, 2)+pow(data[i].second-data[j].second, 2));
			}
		}
		vector<double> data3(n);
		for (int i = 0; i < n; i++) {
			data3[i] = sqrt(pow(data[i].first, 2)+pow(data[i].second, 2));
		}
		queue<Q> q;
		q.push(Q(P(hx, hy), R(0.0, 0)));
		bool hantei = false;
		while (!q.empty()) {
			Q p = q.front();
			q.pop();
			P xy = p.first;
			R limit = p.second;
			for (int i = 0; i < n; i++) {
				bool hantei2 = true;
				if ((limit.second & (1<<i)) == 0) {
					double dead = limit.first+sqrt(pow(data[i].first-xy.first, 2)+pow(data[i].second-xy.second, 2));
					if (data3[i] > dead) {
						int k = limit.second | (1<<i);
						if (k == (1<<n)-1) {
							hantei = true;
							break;
						}
						for (int j = 0; j < n; j++) {
							if ((k & (1<<j)) == 0) {
								if (data3[j] <= dead+data2[i][j]) {
									hantei2 = false;
									break;
								} 
							}
						}
						if (hantei2) {
							q.push(Q(data[i], R(dead, k)));
						}
					}
				}
			}
			if (hantei) {
				break;
			}
		}
		if (hantei) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}
	return 0;
}
accuracy: 1
time_ms: 4340
memory_kb: 13744
final_rank: 18

code_snippet: #include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <unordered_map>
#include <iterator>
#include <functional>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;
double x[21], y[21], t[21], hx, hy, sx ,sy;

double hypot(double x, double y){
	return sqrt(x*x+y*y);
}
int solve(double sx, double sy, int b, double ct){
	if(b == (1<<n)-1) return 1;
	REP(i, n)if(0 == ((b>>i)&1)){
		double nt = ct + hypot(x[i]-sx, y[i]-sy);
		if(t[i]-EPS < nt) return 0;
	}
	REP(i, n)if(0 == ((b>>i)&1)){
		double nt = ct + hypot(x[i]-sx, y[i]-sy);
		if(t[i]-EPS < nt) continue;
		if(solve(x[i], y[i], b | (1<<i), nt)) return 1;
	}
	return 0;
}


int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	while(cin >> n >> sx >> sy >> hx >> hy, n){
		REP(i, n){
			cin >> x[i] >> y[i];
			t[i] = hypot(x[i]-hx, y[i] - hy);
		}
		cout << (solve(sx, sy, 0, 0) ? "YES" : "NO") << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 210
memory_kb: 1228
final_rank: 2