結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー momoharamomohara
提出日時 2020-05-29 21:44:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 308 ms / 2,000 ms
コード長 2,626 bytes
コンパイル時間 1,949 ms
コンパイル使用メモリ 176,144 KB
実行使用メモリ 34,104 KB
最終ジャッジ日時 2024-04-23 21:03:21
合計ジャッジ時間 8,031 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 125 ms
19,200 KB
testcase_03 AC 175 ms
34,104 KB
testcase_04 AC 170 ms
33,588 KB
testcase_05 AC 124 ms
33,460 KB
testcase_06 AC 130 ms
33,584 KB
testcase_07 AC 42 ms
11,264 KB
testcase_08 AC 143 ms
32,640 KB
testcase_09 AC 14 ms
6,144 KB
testcase_10 AC 63 ms
16,512 KB
testcase_11 AC 47 ms
12,544 KB
testcase_12 AC 24 ms
11,008 KB
testcase_13 AC 147 ms
22,508 KB
testcase_14 AC 160 ms
26,304 KB
testcase_15 AC 193 ms
29,064 KB
testcase_16 AC 80 ms
17,808 KB
testcase_17 AC 206 ms
31,156 KB
testcase_18 AC 52 ms
14,040 KB
testcase_19 AC 212 ms
29,656 KB
testcase_20 AC 44 ms
10,524 KB
testcase_21 AC 65 ms
16,844 KB
testcase_22 AC 173 ms
27,652 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 22 ms
10,496 KB
testcase_26 AC 100 ms
18,992 KB
testcase_27 AC 94 ms
18,776 KB
testcase_28 AC 182 ms
29,176 KB
testcase_29 AC 16 ms
8,064 KB
testcase_30 AC 188 ms
31,916 KB
testcase_31 AC 136 ms
24,856 KB
testcase_32 AC 78 ms
16,600 KB
testcase_33 AC 205 ms
32,356 KB
testcase_34 AC 67 ms
13,880 KB
testcase_35 AC 201 ms
32,136 KB
testcase_36 AC 3 ms
5,376 KB
testcase_37 AC 4 ms
5,376 KB
testcase_38 AC 3 ms
5,376 KB
testcase_39 AC 3 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 308 ms
34,000 KB
testcase_42 AC 67 ms
12,928 KB
testcase_43 AC 132 ms
19,692 KB
testcase_44 AC 41 ms
9,472 KB
testcase_45 AC 134 ms
19,328 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);++i)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);--i)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
//constexpr long long MOD = (ll) 1e9 + 7;
constexpr long long MOD = 998244353LL;
using ld=long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

struct Edge {
	ll to, rev;
    long double cap;
	Edge(ll _to, long double _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, long double cap, bool revFlag, long double revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

using P2 = pair<long double, ll>;

void Dijkstra(Graph& G, ll s, vec<long double>& d) {//O(|E|log|V|)
  d.resize(G.size());
  REP(i, d.size())d[i] = INF;
  d[s] = 0;
  priority_queue<P2, vector<P2>, greater<P2>> q;
  q.push(make_pair(0.0L, s));
  while (!q.empty()) {
    P a = q.top();
    q.pop();
    if (d[a.second] < a.first)continue;
    REP(i, G[a.second].size()) {
      Edge e = G[a.second][i];
      if (d[e.to] > d[a.second] + e.cap) {
        d[e.to] = d[a.second] + e.cap;
        q.push(make_pair(d[e.to], e.to));
      }
    }
  }
}



void solve(){
    ll n,m,x,y;
    cin>>n>>m>>x>>y;
    x--;y--;
    vec<long double> p(n),q(n);
    REP(i,n) cin>>p[i]>>q[i];

    auto dis = [&](int i, int j){
        return sqrt((p[i]-p[j])*(p[i]-p[j])+(q[i]-q[j])*(q[i]-q[j]));
    };
    Graph g(n);
    REP(i,m){
        ll a,b;
        cin>>a>>b;
        a--;b--;
        add_edge(g,a,b,dis(a,b),true,dis(a,b));
    }
    vec<long double> d;
    Dijkstra(g,x,d);
    cout<<fixed<<setprecision(10)<<d[y]<<en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	
	solve();
	//ll t;cin>>t;REP(i,t) solve();

    return 0;
}
0