結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー バイトバイト
提出日時 2020-05-30 13:34:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 279 ms / 2,000 ms
コード長 35,249 bytes
コンパイル時間 2,782 ms
コンパイル使用メモリ 213,896 KB
実行使用メモリ 67,428 KB
最終ジャッジ日時 2023-08-07 08:54:15
合計ジャッジ時間 9,892 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 139 ms
32,260 KB
testcase_03 AC 179 ms
65,092 KB
testcase_04 AC 178 ms
67,428 KB
testcase_05 AC 135 ms
62,528 KB
testcase_06 AC 137 ms
64,556 KB
testcase_07 AC 39 ms
17,692 KB
testcase_08 AC 138 ms
59,728 KB
testcase_09 AC 15 ms
9,120 KB
testcase_10 AC 66 ms
28,856 KB
testcase_11 AC 44 ms
19,680 KB
testcase_12 AC 39 ms
24,612 KB
testcase_13 AC 151 ms
48,444 KB
testcase_14 AC 176 ms
52,252 KB
testcase_15 AC 205 ms
54,928 KB
testcase_16 AC 97 ms
35,764 KB
testcase_17 AC 223 ms
60,908 KB
testcase_18 AC 68 ms
27,440 KB
testcase_19 AC 207 ms
56,688 KB
testcase_20 AC 49 ms
17,460 KB
testcase_21 AC 82 ms
34,640 KB
testcase_22 AC 191 ms
53,992 KB
testcase_23 AC 3 ms
4,452 KB
testcase_24 AC 4 ms
4,696 KB
testcase_25 AC 36 ms
24,388 KB
testcase_26 AC 103 ms
33,536 KB
testcase_27 AC 110 ms
36,252 KB
testcase_28 AC 198 ms
60,992 KB
testcase_29 AC 26 ms
15,036 KB
testcase_30 AC 203 ms
57,860 KB
testcase_31 AC 136 ms
43,460 KB
testcase_32 AC 89 ms
28,724 KB
testcase_33 AC 194 ms
58,604 KB
testcase_34 AC 72 ms
27,876 KB
testcase_35 AC 194 ms
59,588 KB
testcase_36 AC 3 ms
4,376 KB
testcase_37 AC 3 ms
4,376 KB
testcase_38 AC 3 ms
4,380 KB
testcase_39 AC 4 ms
4,376 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 279 ms
59,308 KB
testcase_42 AC 70 ms
20,400 KB
testcase_43 AC 138 ms
32,880 KB
testcase_44 AC 46 ms
15,836 KB
testcase_45 AC 140 ms
31,976 KB
testcase_46 AC 1 ms
4,376 KB
testcase_47 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//tempa
//#pragma GCC optimize ("-O3")
#ifdef _DEBUG
#include<cassert>
#include "bits_stdc++.h"
#else
#include <bits/stdc++.h>
#endif

#define t_T template<class T>

using namespace std;
//@起動時
struct initon {
    initon() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.setf(ios::fixed);
        cout.precision(16);
        srand((unsigned) clock() + (unsigned) time(NULL));
    };
} __initon;
//衝突対策
#define ws ___ws
#define over4(o1, o2, o3, o4, name, ...) name

#define int long long
#define ll long long
#define double long double
#define ull unsigned long long
using dou = double;
using itn = int;
using str = string;
using bo= bool;
#define au auto
using P = pair<ll, ll>;

#define fi first
#define se second
#define vec vector
#define beg begin
#define rbeg rbegin
#define con continue
#define bre break
#define brk break
#define is ==
using vi = vector<ll>;
using vb = vector<bool>;
using vs = vector<string>;
using vd = vector<double>;
using vc = vector<char>;
using vp = vector<P>;

//#define V vector
#define vvt0(t) vector<vector<t>>
#define vvt1(t, a) vector<vector<t>>a
#define vvt2(t, a, b) vector<vector<t>>a(b)
#define vvt3(t, a, b, c) vector<vector<t>> a(b,vector<t>(c))
#define vvt4(t, a, b, c, d) vector<vector<t>> a(b,vector<t>(c,d))

#define vvi(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(ll,__VA_ARGS__)
#define vvb(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(bool,__VA_ARGS__)
#define vvs(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(string,__VA_ARGS__)
#define vvd(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(double,__VA_ARGS__)
#define vvc(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(char,__VA_ARGS__)
#define vvp(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(P,__VA_ARGS__)


#define v3i(a, b, c, d) vector<vector<vi>> a(b, vector<vi>(c, vi(d)))
#define v3d(a, b, c, d) vector<vector<vd>> a(b, vector<vd>(c, vd(d)))
#define v3m(a, b, c, d) vector<vector<vm>> a(b, vector<vm>(c, vm(d)))


#define PQ priority_queue<ll, vector<ll>, greater<ll> >
#define tos to_string

using mapi = map<int, int>;
using mapd = map<dou, int>;
using mapc = map<char, int>;
using maps = map<str, int>;
using seti = set<int>;
using setd = set<dou>;
using setc = set<char>;
using sets = set<str>;
using qui = queue<int>;
#define bset bitset
#define uset unordered_set
#define mset multiset
#define umap unordered_map
#define umapi unordered_map<int,int>
#define umapp unordered_map<P,int>
#define mmap multimap

//マクロ 繰り返し
#define _overloadrep(_1, _2, _3, _4, name, ...) name
# define _rep(i, n) for(int i = 0,_lim=n; i < _lim ; i++)
#define repi(i, m, n) for(int i = m,_lim=n; i < _lim ; i++)
#define repadd(i, m, n, ad) for(int i = m,_lim=n; i < _lim ; i+= ad)
#define rep(...) _overloadrep(__VA_ARGS__,repadd,repi,_rep,)(__VA_ARGS__)
#define _rer(i, n) for(int i = n; i >= 0 ; i--)
#define reri(i, m, n) for(int i = m,_lim=n; i >= _lim ; i--)
#define rerdec(i, m, n, dec) for(int i = m,_lim=n; i >= _lim ; i-=dec)
#define rer(...) _overloadrep(__VA_ARGS__,rerdec,reri,_rer,)(__VA_ARGS__)
#define fora(a, b) for(auto&& a : b)

//マクロ 定数
#define k3 1010
#define k4 10101
#define k5 101010
#define k6 1010101
#define k7 10101010


template<class T> T MAX() { return numeric_limits<T>::max(); }
template<class T> T MIN() { return numeric_limits<T>::min(); }
const int inf = (int) 1e9 + 100;
const ll linf = (ll) 1e18 + 100;
t_T T INF() { return MAX<T>() / 2; }
template<> signed INF() { return inf; }
template<> ll INF() { return linf; }
template<> double INF() { return (double) linf * linf; }

const double eps = 1e-9;
const double PI = 3.1415926535897932384626433832795029L;
ll ma = numeric_limits<ll>::min();
ll mi = numeric_limits<ll>::max();
const int y4[] = {-1, 1, 0, 0};
const int x4[] = {0, 0, -1, 1};
const int y8[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int x8[] = {1, 0, -1, 0, 1, -1, 1, -1};

//マクロ省略形 関数等
#define sz(a) ((int)(a).size())
#define rs resize
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

/*@formatter:off*/
inline void sort(string &a) { sort(all(a)); }
t_T inline void sort(vector<T> &a) { sort(all(a)); };
t_T inline void rsort(vector<T> &a) { sort(all(a), greater<T>()); };
template<class U> inline void sortp(vector<U> &a, vector<U> &b) {    vp c;    int n = sz(a);    assert(n == sz(b));    rep(i, n)c.eb(a[i], b[i]);    sort(c);    rep(i, n) {        a[i] = c[i].first;        b[i] = c[i].second;;    }};//F = T<T>
//例えばreturn p.fi + p.se;
template<class U> inline void rsortp(vector<U> &a, vector<U> &b) {    vp c;    int n = sz(a);    assert(n == sz(b));    rep(i, n)c.eb(a[i], b[i]);    rsort(c);    rep(i, n) {        a[i] = c[i].first;        b[i] = c[i].second;    }};
template<typename V, typename T>
void fill(V &xx, const T vall) {xx = vall;}
template<typename V, typename T>
void fill(vector<V> &vecc, const T vall) {for (auto &&vx: vecc) fill(vx, vall);}

//@汎用便利関数 入力
template<typename T = int> T _in() {T x;cin >> x;return (x);}
#define _overloadin(_1, _2, _3, _4, name, ...) name
#define in0() _in()
#define in1(a) cin>>a
#define in2(a, b) cin>>a>>b
#define in3(a, b, c) cin>>a>>b>>c
#define in4(a, b, c, d) cin>>a>>b>>c>>d
#define in(...) _overloadin(__VA_ARGS__,in4,in3,in2 ,in1,in0)(__VA_ARGS__)

#define _overloaddin(_1, _2, _3, _4, name, ...) name
#define din1(a) int a;cin>>a
#define din2(a, b) int a,b;cin>>a>>b
#define din3(a, b, c) int a,b,c;cin>>a>>b>>c
#define din4(a, b, c, d) int a,b,c,d;cin>>a>>b>>c>>d
#define din(...) _overloadin(__VA_ARGS__,din4,din3,din2 ,din1)(__VA_ARGS__)

#define _overloaddind(_1, _2, _3, _4, name, ...) name
#define din1d(a) int a;cin>>a;a--
#define din2d(a, b) int a,b;cin>>a>>b;a--,b--
#define din3d(a, b, c) int a,b,c;cin>>a>>b>>c;a--,b--,c--
#define din4d(a, b, c, d) int a,b,c,d;cin>>a>>b>>c>>d;;a--,b--,c--,d--
#define dind(...) _overloaddind(__VA_ARGS__,din4d,din3d,din2d ,din1d)(__VA_ARGS__)
template<typename W, typename H> void resize(W &vec_, const H head) { vec_.resize(head); }
template<typename W, typename H, typename ... T> void resize(W &vec_, const H &head, const T ... tail) {vec_.resize(head);for (auto &v: vec_)resize(v, tail...);}


string sin() { return _in<string>(); }
ll lin() { return _in<ll>(); }
t_T void na(vector<T> &a, ll n) {a.resize(n);rep(i, n)cin >> a[i];}
#define dna(a, n) vi a; na(a, n);/*nを複数使うと n==in()の時バグる事に注意*/
#define dnad(a, n) vi a; nad(a, n);
t_T void nad(vector<T> &a, ll n) {a.resize(n);rep(i, n)cin >> a[i], a[i]--;}
template<class T, class U> void na2(vector<T> &a, vector<U> &b, ll n) {a.resize(n);b.resize(n);rep(i, n)cin >> a[i] >> b[i];}
#define dna2(a, b, n) vi a,b; na2(a,b,n);
template<class T, class U, class W> void na3(vector<T> &a, vector<U> &b, vector<W> &c, ll n) {a.resize(n);b.resize(n);c.resize(n);rep(i, n)cin >> a[i] >> b[i] >> c[i];}
#define nt(a, h, w) resize(a,h,w);rep(nthi,h)rep(ntwi,w) cin >> a[nthi][ntwi];
#define ntd(a, h, w) resize(a,h,w);rep(ntdhi,h)rep(ntdwi,w) cin >> a[ntdhi][ntdwi], a[ntdhi][ntdwi]--;
#define ntp(a, h, w) resize(a,h+2,w+2);fill(a,'#');rep(ntphi,1,h+1)rep(ntpwi,1,w+1) cin >> a[ntphi][ntpwi];
#define dnt(S, h, w) vvi(S,h,w);nt(S,h,w);
#define dntc(S, h, w) vvc(S,h,w);nt(S,h,w);
#define dnts(S, h, w) vvs(S,h,w);nt(S,h,w);

#define require_t(bo) enable_if_t<bo>* = nullptr

//デバッグ
#define sp << " " <<
constexpr int DEB_LEN =20;
constexpr int DEB_LEN_H =12;
string deb_tos(const int &v) { if (abs(v) == inf || abs(v) == linf)return "e"; else return to_string(v); }
template<class T, require_t(!is_integral<T>::value)> string deb_tos(const T &a) {stringstream ss;ss << a;return ss.str();}
template<class T> string deb_tos(const vector<T> &a, ll W = inf) {    stringstream ss;    if (W == inf)W = min(sz(a), DEB_LEN);    if (sz(a) == 0)return ss.str();    rep(i, W) {        ss << deb_tos(a[i]);        if (typeid(a[i]) == typeid(P)) { ss << endl; } else { ss << " "; }    }    return ss.str();}
template<class T> string deb_tos(const vector<vector<T> > &a, vi H, vi W, int key = -1) {    stringstream ss;    ss << endl;    vi lens(sz(W));    fora(h, H) {        rep(wi, sz(W)) {            lens[wi] = max(lens[wi], sz(deb_tos(a[h][W[wi]])) + 1);            lens[wi] = max(lens[wi], sz(deb_tos(W[wi])) + 1);        }    }    if (key == -1)ss << " *|"; else ss << " " << key << "|";    int wi = 0;    fora(w, W) {        ss << std::right << std::setw(lens[wi]) << w;        wi++;    }    ss << "" << endl;    rep(i, sz(W))rep(_, lens[i]) ss << "_";    rep(i, 3)ss << "_";    ss << "" << endl;    fora(h, H) {        ss << std::right << std::setw(2) << h << "|";        int wi = 0;        fora(w, W) {            ss << std::right << std::setw(lens[wi]) << deb_tos(a[h][w]);            wi++;        }        ss << "" << endl;    }    return ss.str();}
template<class T> string deb_tos(const vector<vector<T> > &a, ll H = inf, ll W = inf, int key = -1) {    H = (H != inf) ? H : min({H, sz(a), DEB_LEN_H});    W = min({W, sz(a[0]), DEB_LEN_H});    vi hs, ws;    rep(h, H) { hs.push_back(h); }    rep(w, W) { ws.push_back(w); }    return deb_tos(a, hs, ws, key);}
template<class T> string deb_tos(const vector<vector<vector<T> > > &a, ll H = inf) {    stringstream ss;    if (H == inf)H = DEB_LEN_H;    H = min(H, sz(a));    rep(i, H) {        ss << endl;        ss << deb_tos(a[i], inf, inf, i);    }    return ss.str();}
template<class T, size_t A> string deb_tos(T (&a)[A]) { return deb_tos(vector<T>(begin(a), end(a))); }
template<class T, size_t A, size_t B> string deb_tos(T (&a)[A][B]) { return deb_tos(vector<vector<T> >(begin(a), end(a))); }
template<class T, size_t A, size_t B, size_t C> string deb_tos(T (&a)[A][B][C]) { return deb_tos(vector<vector<vector<T> > >(begin(a), end(a))); }

#define debugName(VariableName) # VariableName

#define _deb1(x) cerr <<  debugName(x)<<" = "<<deb_tos(x) << endl
#define _deb2(x, y) cerr <<  debugName(x)<<" = "<<deb_tos(x)<<", "<< debugName(y)<<" = "<<deb_tos(y)<< endl
#define _deb3(x, y, z) cerr <<  debugName(x)<<" = "<<deb_tos(x)  << ", " <<  debugName(y)<<" = "<<deb_tos(y) <<", " debugName(z)<<" = "<<deb_tos(z) <<endl
#define _deb4(x, y, z, a) cerr <<  debugName(x)<<" = "<<deb_tos(x) <<", " <<   debugName(y)<<" = "<<deb_tos(y) <<", " <<  debugName(z)<<" = "<<deb_tos(z) <<", " <<  debugName(a)<<" = "<<deb_tos(a)<<endl
#define _deb5(x, y, z, a, b) cerr <<  debugName(x)<<" = "<<deb_tos(x) <<", " <<   debugName(y)<<" = "<<deb_tos(y) <<", " <<  debugName(z)<<" = "<<deb_tos(z) <<", " <<  debugName(a)<<" = "<<deb_tos(a)<<", " <<  debugName(b)<<" = "<<deb_tos(b)<<endl


#define _overloadebug(_1, _2, _3, _4, _5, name, ...) name
#define debug(...) _overloadebug(__VA_ARGS__,_deb5,_deb4,_deb3,_deb2,_deb1)(__VA_ARGS__)
#ifdef _DEBUG
#define deb(...) _overloadebug(__VA_ARGS__,_deb5,_deb4,_deb3,_deb2,_deb1)(__VA_ARGS__)
#else
#define deb(...) ;
#endif


#define debugline(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n'


ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll gcd(vi b) {ll res = b[0];for (auto &&v :b)res = gcd(v, res);return res;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll rev(ll a) {    ll res = 0;    while (a) {        res *= 10;        res += a % 10;        a /= 10;    }    return res;}
template<class T> auto rev(const T &v, int i) {return v[sz(v) - 1 - i];}
t_T vector<T> rev(vector<T> &a) {    auto b = a;    reverse(all(b));    return b;}
str rev(str &a) {str s = a;reverse(all(s));return s;}
ll ceil(ll a, ll b) {if (b == 0) {cerr<<"ceil"<<endl;exit(1);return -1;} else return (a + b - 1) / b;}
ll sqrt(ll a) {    if (a < 0) {        cerr<<"sqrt"<<endl;        exit(1);    }    ll res = (ll) std::sqrt(a);    while (res * res < a)res++;    return res;}
double log(double e, double x) { return log(x) / log(e); }
ll sig(ll t) { return (1 + t) * t / 2; }
ll sig(ll s, ll t) { return (s + t) * (t - s + 1) / 2; }

vi divisors(int v) {    vi res;    double lim = std::sqrt(v);    rep(i, 1, lim+1){        if (v % i == 0) {            res.pb(i);            if (i != v / i)res.pb(v / i);        }    }    return res;}
vb isPrime;
vi primes;

void setPrime() {    int len = 4010101;    isPrime.resize(4010101);    fill(isPrime, true);    isPrime[0] = isPrime[1] = false;    for (int i = 2; i <= sqrt(len) + 5; ++i) {        if (!isPrime[i])continue;        for (int j = 2; i * j < len; ++j) {            isPrime[i * j] = false;        }    }    rep(i, len)if (isPrime[i])primes.pb(i);}

vi factorization(int v) {    int tv = v;    vi res;    if (isPrime.size() == 0)setPrime();    for (auto &&p :primes) {        if (v % p == 0)res.push_back(p);        while (v % p == 0) {            v /= p;        }        if (v == 1 || p * p > tv)break;    }    if (v > 1)res.pb(v);    return res;}
inline bool inside(int h, int w, int H, int W) { return h >= 0 && w >= 0 && h < H && w < W; }
inline bool inside(int v, int l, int r) { return l <= v && v < r; }


t_T vector<T> ruiv(vector<T> &a) {    vector<T> ret(a.size() + 1);    rep(i, a.size())ret[i + 1] = ret[i] + a[i];    return ret;}
//imoは0-indexed
//ruiは1-indexed
t_T vector<T> imo(vector<T> &v) {    vector<T> ret = v;    rep(i, sz(ret) - 1)ret[i + 1] += ret[i];    return ret;}

#define ins inside
ll u0(ll a) { return a < 0 ? 0 : a; }
t_T vector<T> u(const vector<T> &a) {
    vector<T> ret = a;fora(v, ret)v = u0(v);return ret;}
template<class T, class U> pair<T,U> operator+(const pair<T,U> &a, const pair<T,U> & b) {return pair<T,U>(a.fi+b.fi,a.se+b.se);}

void yn(bool a) {
    if (a)cout << "yes" << endl;
    else cout << "no" << endl;
}
void Yn(bool a) {
    if (a)cout << "Yes" << endl;
    else cout << "No" << endl;
}
void YN(bool a) {
    if (a)cout << "YES" << endl;
    else cout << "NO" << endl;
}
void fyn(bool a) {
    if (a)cout << "yes" << endl;
    else cout << "no" << endl;
    exit(0);
}
void fYn(bool a) {
    if (a)cout << "Yes" << endl;
    else cout << "No" << endl;
    exit(0);
}
void fYN(bool a) {
    if (a)cout << "YES" << endl;
    else cout << "NO" << endl;
    exit(0);
}
void Possible(bool a) {
    if (a)cout << "Possible" << endl;
    else cout << "Impossible" << endl;
    exit(0);
}
void POSSIBLE(bool a) {
    if (a)cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
    exit(0);
}
template<class T, class U> set<T> &operator+=(set<T> &a, U v) {
    a.insert(v);
    return a;
}
template<class T, class U> vector<T> &operator+=(vector<T> &a, U v) {
    a.push_back(v);
    return a;
}
template<class T> vector<T>& operator+=(vector<T> & a,const vector<T> & b){
    rep(i, sz(b))a += b[i];
    return a;
}
t_T T sum(vector<T> &v, int s = 0, int t = inf) {    T ret = 0;    rep(i, s, min(sz(v), t))ret += v[i];    return ret;}
void mod(int &a, int m) { a = (a % m + m) % m; }
template<class F> inline int mgr(int ok, int ng, F f) {
#define _mgrbody int mid = (ok + ng) / 2; if (f(mid))ok = mid; else ng = mid;
    if (ok < ng)while (ng - ok > 1) { _mgrbody } else while (ok - ng > 1) { _mgrbody }
    return ok;
}

template<class F> inline int mgr(int ok, int ng, int second, F f) {
#define _mgrbody2 int mid = (ok + ng) / 2; if (f(mid, second))ok = mid; else ng = mid;
    if (ok < ng) while (ng - ok > 1) { _mgrbody2 } else while (ok - ng > 1) { _mgrbody2 }
    return ok;
}
template<typename T> ostream &operator<<(ostream &os, vector<T> &m) {    rep(i, sz(m)){os << m[i];if(i < sz(m)-1)os<<" ";}   return os;}
ostream &operator<<(ostream &os, vector<char> &m) {rep(i, sz(m)){os << m[i];}   return os;}
template<typename T> ostream &operator<<(ostream &os, vector<vector<T>> &m) {rep(i, sz(m)){os << m[i]; if(i < sz(m)-1)os << endl;}   return os;}
constexpr bool bget(ll m, int keta) { return (m >> keta) & 1; }
int bget(ll m, int keta, int sinsuu) {m /= (ll) pow(sinsuu, keta);return m % sinsuu;}
ll bit(int n) { return (1LL << (n)); }
ll bit(int n, int sinsuu) { return (ll) pow(sinsuu, n); }
int mask(int n) { return (1ll << n) - 1; }
#define bcou __builtin_popcountll
template<class T, class U> inline bool chma(T &a, const U &b) {if (a < b) {a = b;return true;}return false;}
template<class U> inline bool chma(const U &b) { return chma(ma, b); }
template<class T, class U> inline bool chmi(T &a, const U &b) {    if (b < a) {        a = b;        return true;    }    return false;}
template<class U> inline bool chmi(const U &b) { return chmi(mi, b); }
#define unique(v) v.erase( unique(v.begin(), v.end()), v.end() );
int max(vi &a) {    int res = a[0];    fora(v, a) {        res = max(res, v);    }    return res;}
int min(vi &a) {    int res = a[0];    fora(v, a) {        res = min(res, v);    }    return res;}
template<typename T> class fixed_point        : T {public:    explicit constexpr fixed_point(T &&t) noexcept: T(std::forward<T>(t)) {}    template<typename... Args> constexpr decltype(auto) operator()(Args &&... args) const { return T::operator()(*this, std::forward<Args>(args)...); }};template<typename T> static inline constexpr decltype(auto) fix(T &&t) noexcept { return fixed_point<T>{std::forward<T>(t)}; }
constexpr ll h4[] = {1, -1, 0, 0};
constexpr ll w4[] = {0, 0, -1, 1};
constexpr ll h8[] = {0, 1, 0, -1, -1, 1, 1, -1};
constexpr ll w8[] = {1, 0, -1, 0, 1, -1, 1, -1};
int mei_inc(int h, int w, int H, int W, int i) {while (++i < 4) { if (inside(h + h4[i], w + w4[i], H, W))return i; }return i;}
#define mei(nh, nw, h, w) for (int i = mei_inc(h, w, H, W, -1), nh = i<4? h + h4[i] : 0, nw = i<4? w + w4[i] : 0; i < 4; i=mei_inc(h,w,H,W,i), nh = h+h4[i], nw = w+w4[i])
int mei_inc8(int h, int w, int H, int W, int i) {    while (++i < 8) {        if (inside(h + h8[i], w + w8[i], H, W))return i;    }    return i;}
#define mei8(nh, nw, h, w) for (int i = mei_inc8(h, w, H, W, -1), nh = i<8? h + h8[i] : 0, nw = i<8? w + w8[i] : 0; i < 8; i=mei_inc8(h,w,H,W,i), nh = h+h8[i], nw = w+w8[i])
int mei_incv(int h, int w, int H, int W, int i, vp &p) {    while (++i < sz(p)) { if (inside(h + p[i].fi, w + p[i].se, H, W))return i; }    return i;}
#define meiv(nh, nw, h, w, p) for (int i = mei_incv(h, w, H, W, -1, p), nh = i<sz(p)? h + p[i].fi : 0, nw = i<sz(p)? w + p[i].se : 0; i < sz(p); i=mei_incv(h,w,H,W,i,p), nh = h+p[i].fi, nw = w+p[i].se)
vi compress(vi &A) {    vi B = A;    sort(B);    unique(B);    vi inds(sz(B));    rep(i, sz(A)) {        int ind = lower_bound(all(B), A[i]) - B.begin();        inds[ind] = A[i];        A[i] = ind;    }    return inds;}
vi compress(vi &A, umapi& map){    vi i_v = compress(A);    rep(i, sz(i_v)){        map[i_v[i]] = i;    }    return i_v;}

t_T void out2(T head) {    cout << head;}
template<class T, class... U> void out2(T head, U ... tail) {    cout << head << " ";      out2(tail...);}
template<class T, class... U> void out(T head, U ... tail) {    cout << head << " ";        out2(tail...);    cout << "" << endl;}
t_T void out(T head) {    cout << head << endl; }
void out() { cout << "" << endl; }
#define lowerIndex(a, v) (lower_bound(all(a),v)-a.begin())
#define upperIndex(a, v) (uppereturnbound(all(a),v)-a.begin())
template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
#define vni(name, ...) auto name = make_v<ll>(__VA_ARGS__)
#define vnb(name, ...) auto name = make_v<bool>(__VA_ARGS__)
#define vns(name, ...) auto name = make_v<string>(__VA_ARGS__)
#define vnd(name, ...) auto name = make_v<double>(__VA_ARGS__)
#define vnc(name, ...) auto name = make_v<char>(__VA_ARGS__)
#define vnp(name, ...) auto name = make_v<P>(__VA_ARGS__)
#define vn(type, name, ...) auto name = make_v<type>(__VA_ARGS__)
#define VEC vector

/*@formatter:on*/
int N, M, H, W;
vi A, B, C;

//@formatter:off
//よく使うクラス、構造体
struct unionfind {
    vector<ll> par;
    vector<ll> siz;
    vector<ll> es;
    ll n, trees;//連結グループの数(親の種類)
    unionfind(ll n) : n(n), trees(n) {        par.resize(n);        siz.resize(n);        es.resize(n);        for (ll i = 0; i < n; i++) {            par[i] = i;            siz[i] = 1;        }    }
    ll root(ll x) { if (par[x] == x) { return x; } else { return par[x] = root(par[x]); }}
    bool unite(ll x, ll y) {
        x = root(x);
        y = root(y);
        es[x]++;
        if (x == y) return false;
        if (siz[x] > siz[y]) swap(x, y);
        trees--;
        par[x] = y;
        siz[y] += siz[x];
        es[y] += es[x];
        return true;
    }
    bool same(ll x, ll y) { return root(x) == root(y); }
    ll size(ll x) { return siz[root(x)]; }
    ll esize(ll x) { return es[root(x)]; }
    vi sizes(){        vi cou(n);        vi ret;        ret.reserve(n);        rep(i, n){            cou[root (i)]++;        }        rep(i, n){            if(cou[i])ret.push_back(cou[i]);        }        return ret;    }
    //つながりを無向グラフと見なし、xが閉路に含まれるか判定
    bool close(ll x) { return esize(x) >= size(x); }
    vec<vi> sets() {        vi ind(n, -1);        ll i = 0;        vvi(res, trees);        rep(j, n) {            ll r = root(j);            if (ind[r] == -1)ind[r] = i++;            res[ind[r]].push_back(j);        }        rep(i, trees) {            ll r = root(res[i][0]);            if (res[i][0] == r)continue;            rep(j, 1, sz(res[i])) {                if (res[i][j] == r) {                    swap(res[i][0], res[i][j]);                    break;                }            }        }        return res;    }
};
/*@formatter:off*/
#define forg(gi, ve) for (ll gi = 0,forglim = ve.size(), f, t, c; gi < forglim && (f = ve[gi].f, t = ve[gi].t, c = ve[gi].c, true); ++gi)
#define fort(gi, ve) for (ll gi = 0, f, t, c; gi < ve.size() && (f = ve[gi].f, t = ve[gi].t, c = ve[gi].c, true); ++gi)if(t!=p)
#define fore(gi, ve) for (ll gi = 0,forglim = ve.size(), f, t, c,ty, id; gi < forglim && (f = ve[gi].f, t = ve[gi].t, c = ve[gi].c, id=ve[gi].id, ty = ve[gi].ty, true); ++gi)

//typeが追加される
#define forg2(gi, ve) for (ll gi = 0,forglim = ve.size(), f, t, c,ty; gi < forglim && (f = ve[gi].f, t = ve[gi].t, c = ve[gi].c,ty=ve[gi].ty, true); ++gi)
#define fort2(gi, ve) for (ll gi = 0, f, t, c,ty; gi < ve.size() && (f = ve[gi].f, t = ve[gi].t, c = ve[gi].c,ty=ve[gi].ty, true); ++gi)if(t!=p)
template<class T> struct edge { int f, t; T c; int id; int ty; edge(int f, int t, T c = 1,  int ty = -1,int id = -1) : f(f), t(t), c(c), id(id), ty(ty) {} bool operator<(const edge &b) const { return c < b.c; } bool operator>(const edge &b) const { return c > b.c; }};
template<class T> ostream &operator<<(ostream &os, edge<T> &e) {    os << e.f << " " << e.t << " " << e.c;    return os;}
template<typename T> class graph {protected:    vector<bool> usedv;public :    vector<vector<edge<T>>> g;    vector<edge<T>> edges;    int n;    graph(int n) : n(n) { g.resize(n), usedv.resize(n); }    void clear() { g.clear(), edges.clear(); }    void resize(int n) {        this->n = n;        g.resize(n);        usedv.resize(n);    }    int size() { return g.size(); }    vector<edge<T> > &operator[](int i) { return g[i]; }    virtual void add(int f, int t, T c, int ty ,int id) = 0;    virtual bool used(edge<T> &e) = 0;    virtual bool used(int id) = 0;    virtual void del(edge<T> &e) = 0;    virtual void del(int id) = 0;    virtual void set_edges() = 0;};
template<typename T =ll> class digraph : public graph<T> {
public:
    using graph<T>::g;
    using graph<T>::n;
    using graph<T>::edges;
    using graph<T>::usedv;
    int eid = 0;

    digraph(int n) : graph<T>(n) {}
    void add(int f, int t, T c = 1, int ty = -1,int id = -1) {
        if (!(0 <= f && f < n && 0 <= t && t < n)) {
            debugline("digraph add");
            deb(f, t, c, ty,id);
        }
        if (id == -1)id = eid++;
        g[f].emplace_back(f, t, c, ty,id);
        edges.emplace_back(f, t, c, ty,id);
    }
    void ing(int n,int m, int minus = 1) {    this->resize(n);    rep(i, m) {            int f, t;            cin >> f >> t;            f -= minus;            t -= minus;            add(f, t);        }    }
    void ingc(int n,int m, int minus = 1) {   this->resize(n);     rep(i, m) {            int f, t, c;            cin >> f >> t >> c;            f -= minus;            t -= minus;            add(f, t,c);        }    }
    void ingct(int n,int m, int minus = 1) {  this->resize(n);      rep(i, m) {            int f, t, c,ty;            cin >> f >> t >> c>>ty;            f -= minus;            t -= minus;            ty -= minus;            add(f, t,c,ty);        }    }
    void ingtc(int n,int m, int minus = 1) {  this->resize(n);      rep(i, m) {            int f, t, c,ty;            cin >> f >> t >> ty>>c;            f -= minus;            t -= minus;            ty -= minus;            add(f, t,c,ty);        }    }
    bool used(edge<T> &e) { return usedv[e.id]; }
    bool used(int id) { return usedv[id]; }
    void del(edge<T> &e) { usedv[e.id] =  1; }
    void del(int id) { usedv[id] =  1; }
    void set_edges() {        if (sz(edges))return;        rep(i, n)fora(e, g[i])edges.push_back(e);    }
};
template<class T=int> class undigraph : public graph<T> {
public:
    using graph<T>::g;    using graph<T>::n;    using graph<T>::edges;    using graph<T>::usedv;
    int eid = 0;
    undigraph(int n) : graph<T>(n) {}
    // f < t
    void add(int f, int t, T c = 1, int ty = -1, int id = -1) {
        if (!(0 <= f && f < n && 0 <= t && t < n)) {
            debugline("undigraph add");
//            deb(f, t, c, ty, id);
            ;;
        }
        if (id == -1)id = eid++;
        g[f].emplace_back(f, t, c, ty, id);
        g[t].emplace_back(t, f, c, ty, id);
        edges.emplace_back(f, t, c, ty, id);//
        edges.emplace_back(t, f, c, ty, id);
    }
    void add(edge<T> &e) {        int f = e.f, t = e.t, ty = e.ty;        T c = e.c;        add(f, t, c, ty);    }
    void ing(int n,int m, int minus = 1) {      this->resize(n);  rep(i, m) {            int f, t;            cin >> f >> t;            f -= minus;            t -= minus;            add(f, t);        }    }    void ingc(int n, int m, int minus = 1) {rep(i, m) {       this->resize(n);     int f, t, c;            cin >> f >> t >> c;            f -= minus;            t -= minus;            add(f, t, c);        }}
    void ingct(int n,int m, int minus = 1) {     this->resize(n);   rep(i, m) {            int f, t, c, ty;            cin >> f >> t >> c >> ty;            f -= minus;            t -= minus;            ty -= minus;            add(f, t, c, ty);        }    }
    void ingtc(int n,int m, int minus = 1) {      this->resize(n);  rep(i, m) {            int f, t, c, ty;            cin >> f >> t >> ty >> c;            f -= minus;            t -= minus;            ty -= minus;            add(f, t, c, ty);        }    }    bool used(edge<T> &e) { return usedv[e.id]; }
    bool used(int id) { return usedv[id]; }
    void del(edge<T> &e) { usedv[e.id] = 1; }
    void del(int id) { usedv[id] = 1; }
    void set_edges() {        if (sz(edges))return;        rep(i, n)fora(e, g[i])edges.push_back(e);    }
};
template<class T> vector<T> dijkstra(const graph<T> &g, int s, int init_value = -1) {    if (!(0 <= s && s < g.n)) {        debugline("dijkstra");        deb(s, g.n);;;    }    T initValue = MAX<T>();    vector<T> dis(g.n, initValue);    priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> q;    dis[s] = 0;    q.emplace(0, s);    while (q.size()) {        T nowc = q.top().fi;        int i = q.top().se;        q.pop();        if (dis[i] != nowc)continue;        for (auto &&e  : g.g[i]) {            int to = e.t;            T c = nowc + e.c;            if (dis[to] > c) {                dis[to] = c;                q.emplace(dis[to], to);            }        }    }    /*基本、たどり着かないなら-1*/    for (auto &&d :dis) if (d == initValue)d = init_value;    return dis;}
template<class T> vector<vector<T>> dijkstra_all(const graph<T> &g, int init_value = -1) {
    vector<vector<T>> dis(g.n);
    rep(i, g.n) { dis[i] = dijkstra(g, i, init_value); }
    return dis;
}
//ret vector(dis,count); 最短経路とその通りを数える
template<class T> auto dijkstra_cou(const graph<T> &g, int s, int init_value = -1) {if (!(0 <= s && s < g.n)) {        debugline("dijkstra");        deb(s, g.n);;;    }    T initValue = MAX<T>();    vector<T> dis(g.n, initValue);    vi cou(g.n);    cou[0] = 1;    priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> q;    dis[s] = 0;    q.emplace(0, s);    while (q.size()) {        T nowc = q.top().fi;        int i = q.top().se;        q.pop();        if (dis[i] != nowc)continue;        for (auto &&e  : g.g[i]) {            int to = e.t;            T c = nowc + e.c;            if (dis[to] > c) {                dis[to] = c;                cou[to] = cou[e.f];                q.emplace(dis[to], to);            }            else if (dis[to] == c) { cou[to] += cou[e.f]; }        }    }    /*基本、たどり着かないなら-1*/    for (auto &&d :dis) if (d == initValue)d = init_value;    return vtop(dis, cou);}
//コストを無限に減らせる := -linf
//たどり着けない := linf
/*頂点数がkの木を一つ返す サイズが0の木が帰ったら終了*/
//短い版
//13:14
#define use_epsdou
#ifdef use_epsdou
//基本コメントアウト
struct epsdou {
    double v;
    epsdou(double v = 0) : v(v) {}
    template<class T> epsdou &operator+=(T b) {
        v += (double) b;
        return (*this);
    }
    template<class T> epsdou &operator-=(T b) {
        v -= (double) b;
        return (*this);
    }
    template<class T> epsdou &operator*=(T b) {
        v *= (double) b;
        return (*this);
    }
    template<class T> epsdou &operator/=(T b) {
        v /= (double) b;
        return (*this);
    }
    epsdou operator+(epsdou b) { return v + (double) b; }
    epsdou operator-(epsdou b) { return v - (double) b; }
    epsdou operator*(epsdou b) { return v * (double) b; }
    epsdou operator/(epsdou b) { return v / (double) b; }
    epsdou operator-() const { return epsdou(-v); }
    template<class T> bool operator<(T b) { return v < (double) b; }
    template<class T> bool operator>(T b) {
        auto r = (double) b;
        return v > (double) b;
    }
    template<class T> bool operator==(T b) { return fabs(v - (double) b) <= eps; }
    template<class T> bool operator<=(T b) { return v < (double) b || fabs(v - b) <= eps; }
    template<class T> bool operator>=(T b) { return v > (double) b || fabs(v - b) <= eps; }
    operator double() { return v; }
};
template<> epsdou MAX() { return MAX<double>(); }
template<> epsdou MIN() { return MIN<double>(); }
//priqrity_queue等で使うのに必要
bool operator<(const epsdou &a, const epsdou &b) { return a.v < b.v; }
bool operator>(const epsdou &a, const epsdou &b) { return a.v > b.v; }
istream &operator>>(istream &iss, epsdou &a) {
    iss >> a.v;
    return iss;
}
ostream &operator<<(ostream &os, const epsdou &a) {
    os << a.v;
    return os;
}
#define eps_conr_t(o) template<class T> epsdou operator o(T a, epsdou b) {return (dou) a o b.v;}
#define eps_conl_t(o) template<class T> epsdou operator o(epsdou a, T b) {return a.v o (dou) b;}
eps_conl_t(+)
eps_conl_t(-)
eps_conl_t(*)
eps_conl_t(/)
eps_conr_t(+)
eps_conr_t(-)
eps_conr_t(*)
eps_conr_t(/)
//template<class U> epsdou max(epsdou a, U b){return a.v>b ? a.v: b;}
//template<class U> epsdou max(U a, epsdou b){return a>b.v ? a: b.v;}
//template<class U> epsdou min(epsdou a, U b){return a.v<b ? a.v: b;}
//template<class U> epsdou min(U a, epsdou b){return a<b.v ? a: b.v;}
#undef double
#define double epsdou
#undef dou
#define dou epsdou
#endif

vi iota(ll s, ll len) {
    vi ve(len);
    iota(ve.begin(), ve.end(), s);
    return ve;
}
//幾何ライブラリ   *@formatter:off*/
bool eq(double a, double b){return fabs(a-b) < eps;}
vp ort_next_ = {{1, 0}, {0,  1}, {-1, 0}, {0,  -1}, {1,  0}};
vp ort_prev_ = {{1, 0}, {1,  0}, {0, 1}, {-1,  0}, {0,  -1}};
class D {
public:
    double x, y;
    D(): x(0), y(0) {}
    D(double x, double y): x(x), y(y) {}
    D(P p): x(p.first), y(p.second){}
    D& operator+=( D& v) { x += v.x; y += v.y; return *this;}
    D operator+( D& v)  { return D(*this) += v;}
    D& operator-=( D& v) { x -= v.x; y -= v.y; return *this;}
    D operator-( D& v)  { return D(*this) -= v;}
    D& operator*=(double s) { x *= s; y *= s; return *this;}
    D operator*(double s)  { return D(*this) *= s;}
    D& operator/=(double s) { x /= s; y /= s; return *this;}
    D operator/(double s)  { return D(*this) /= s;}
    bool operator==(D & v) {return x == v.x && y == v.y;}
    //内積
    double dot( D& v)  { return x*v.x + y*v.y;}
    //外積
    double cross( D& v)  { return x*v.y - v.x*y;}
    //距離の2乗
    double norm2()  { return x*x + y*y;}
    double norm()  { return sqrt(norm2());}
    //単位ベクトルを返す
    D unit(){return (*this)/ norm();}
    // 象限
    int ort()  {        if (abs(x) < eps && abs(y) <= eps) return 0;        if (y > 0) return x>0 ? 1 : 2;        else return x<0 ? 3 : 4;    }
    //偏角でソート出来る
    bool operator<( D& v)  {        int o = ort(), vo = v.ort();        if (o != vo) return o < vo;        return cross(v) > 0;    }
    bool operator>( D &v)  {        int o = ort(), vo = v.ort();        if (o != vo) return o > vo;        return cross(v) < 0;    }
    //反時計回りで隣接する象限との境界にある、長さ1の点を返す
    //(+,+)で呼ぶと(0, 1)が返る
    D ort_bound_next(){        int i=ort();        assert(i);        return D(ort_next_[i]);    }
    //時計回り
    D ort_bound_prev(){        int i=ort();        assert(i);        return D(ort_prev_[i]);    }
};
using dots = vector<D>;
double dis( D &p,  D &q);

bool eq(D a, D b){ return dis(a,b) <= eps;}

//線分
struct E{
    D f,t;
    E(D f=D(),D t=D()):f(f),t(t){}
};

//円
struct R{
    D o;//中心
    double r;//半径
    R():o(D(0,0)),r(0){}
    R(D o, dou r):o(o),r(r){}
    bool operator==(R b){return b.o == o && b.r == r;}
};

istream& operator>>(istream& ist, D& v) {ist >> v.x >> v.y; return ist;}
istream& operator>>(istream& ist, R& v) {ist >> v.o >> v.r; return ist;}
ostream& operator<<(ostream& os,  D& v) {os<<"("<<v.x<<","<<v.y<<")"; return os;}
ostream& operator<<(ostream& os,  R& v) {os<<"("<<v.o<<","<<v.r<<")"; return os;}
D vect(dou theta, dou len, D a = D());
double arg(D b, D a = D());
//@基本計算 取得***********************************************

//外積
double cross( D p,  D q) { return p.x * q.y - p.y * q.x; }
//距
double dis2( D &p,  D &q){return ((p.x-q.x)*(p.x-q.x)) +(p.y-q.y)*(p.y-q.y) ;}
double dis( D &p,  D &q){return std::sqrt(dis2(p,q)) ;}




void solve() {
    in(N, M);
    dind(X, Y);
    dots pos;
    rep(i, N) {
        din(x, y);
        pos.eb(x, y);
    }
    undigraph<double> g(N);
    rep(_, M) {
        dind(f, t);
        double c = dis(pos[f], pos[t]);
        deb(f, t, c);
        g.add(f, t, c);
    }
    out(dijkstra(g, X, -1)[Y]);
}

signed main() {
    solve();
    return 0;
}
0