結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー どららどらら
提出日時 2020-05-29 21:58:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 295 ms / 2,000 ms
コード長 1,453 bytes
コンパイル時間 1,783 ms
コンパイル使用メモリ 172,884 KB
実行使用メモリ 28,208 KB
最終ジャッジ日時 2024-04-23 22:18:52
合計ジャッジ時間 8,846 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,648 KB
testcase_01 AC 3 ms
9,668 KB
testcase_02 AC 125 ms
14,880 KB
testcase_03 AC 220 ms
25,952 KB
testcase_04 AC 216 ms
28,208 KB
testcase_05 AC 173 ms
27,932 KB
testcase_06 AC 171 ms
26,884 KB
testcase_07 AC 58 ms
11,556 KB
testcase_08 AC 219 ms
20,384 KB
testcase_09 AC 22 ms
9,404 KB
testcase_10 AC 101 ms
13,604 KB
testcase_11 AC 67 ms
11,880 KB
testcase_12 AC 64 ms
15,256 KB
testcase_13 AC 161 ms
18,060 KB
testcase_14 AC 169 ms
19,612 KB
testcase_15 AC 202 ms
22,836 KB
testcase_16 AC 104 ms
16,484 KB
testcase_17 AC 218 ms
21,324 KB
testcase_18 AC 79 ms
16,092 KB
testcase_19 AC 195 ms
20,236 KB
testcase_20 AC 55 ms
12,948 KB
testcase_21 AC 101 ms
16,856 KB
testcase_22 AC 183 ms
20,420 KB
testcase_23 AC 6 ms
8,896 KB
testcase_24 AC 6 ms
9,412 KB
testcase_25 AC 54 ms
13,112 KB
testcase_26 AC 109 ms
15,700 KB
testcase_27 AC 117 ms
16,328 KB
testcase_28 AC 197 ms
22,756 KB
testcase_29 AC 30 ms
11,228 KB
testcase_30 AC 197 ms
23,332 KB
testcase_31 AC 129 ms
17,776 KB
testcase_32 AC 86 ms
14,176 KB
testcase_33 AC 183 ms
21,856 KB
testcase_34 AC 79 ms
14,692 KB
testcase_35 AC 196 ms
21,304 KB
testcase_36 AC 5 ms
8,572 KB
testcase_37 AC 5 ms
8,648 KB
testcase_38 AC 4 ms
9,160 KB
testcase_39 AC 5 ms
8,476 KB
testcase_40 AC 3 ms
9,024 KB
testcase_41 AC 295 ms
21,108 KB
testcase_42 AC 77 ms
12,868 KB
testcase_43 AC 140 ms
15,228 KB
testcase_44 AC 50 ms
11,080 KB
testcase_45 AC 132 ms
15,256 KB
testcase_46 AC 3 ms
8,644 KB
testcase_47 AC 3 ms
8,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

#define MAX_N 200005
struct Edge {
  int src, dest;
  double weight;
};
bool operator>(const Edge& a, const Edge& b){
  return a.weight > b.weight;
}
int N, M;
vector<Edge> G[MAX_N];
double cost[MAX_N];

void dijkstra(int start){
  rep(i,N+1){
    cost[i] = 1e100;
  }
  priority_queue<Edge,vector<Edge>,greater<Edge>> q;
  q.push((Edge){-1,start,0});

  while(!q.empty()){
    Edge e=q.top();
    q.pop();
    if(cost[e.dest] < 1e99) continue;
    cost[e.dest]=e.weight;
    FOR(it,G[e.dest])
      if(cost[it->dest] > 1e99) q.push((Edge){it->src,it->dest,e.weight+it->weight});
  }
}

int main(){
  cin >> N >> M;
  int X, Y;
  cin >> X >> Y;
  vector<pair<int,int>> v;
  v.emplace_back(0,0);
  rep(i,N){
    int p, q;
    cin >> p >> q;
    v.emplace_back(p,q);
  }
  rep(i,M){
    int p, q;
    cin >> p >> q;

    double px = v[p].first;
    double py = v[p].second;
    double qx = v[q].first;
    double qy = v[q].second;
    double dist = sqrt((px-qx)*(px-qx) + (py-qy)*(py-qy));
    G[p].push_back((Edge){p,q,dist});
    G[q].push_back((Edge){q,p,dist});
  }

  dijkstra(X);
  double ret = cost[Y];
  printf("%.12lf\n", ret);
  
  return 0;
}
0