結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー mmn15277198mmn15277198
提出日時 2022-05-02 16:46:32
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 446 ms / 2,000 ms
コード長 1,447 bytes
コンパイル時間 951 ms
コンパイル使用メモリ 103,116 KB
実行使用メモリ 43,064 KB
最終ジャッジ日時 2023-09-14 13:12:08
合計ジャッジ時間 13,458 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 215 ms
18,740 KB
testcase_03 AC 320 ms
43,064 KB
testcase_04 AC 313 ms
41,576 KB
testcase_05 AC 238 ms
41,640 KB
testcase_06 AC 239 ms
40,872 KB
testcase_07 AC 76 ms
10,968 KB
testcase_08 AC 288 ms
32,096 KB
testcase_09 AC 26 ms
5,704 KB
testcase_10 AC 128 ms
16,088 KB
testcase_11 AC 88 ms
12,260 KB
testcase_12 AC 80 ms
15,604 KB
testcase_13 AC 241 ms
25,656 KB
testcase_14 AC 271 ms
26,288 KB
testcase_15 AC 317 ms
32,900 KB
testcase_16 AC 160 ms
20,064 KB
testcase_17 AC 342 ms
31,208 KB
testcase_18 AC 117 ms
18,492 KB
testcase_19 AC 309 ms
29,464 KB
testcase_20 AC 82 ms
10,516 KB
testcase_21 AC 142 ms
20,948 KB
testcase_22 AC 286 ms
28,120 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 5 ms
4,376 KB
testcase_25 AC 71 ms
12,284 KB
testcase_26 AC 176 ms
20,324 KB
testcase_27 AC 185 ms
21,112 KB
testcase_28 AC 316 ms
33,736 KB
testcase_29 AC 39 ms
8,196 KB
testcase_30 AC 316 ms
38,136 KB
testcase_31 AC 213 ms
27,192 KB
testcase_32 AC 139 ms
16,228 KB
testcase_33 AC 302 ms
32,384 KB
testcase_34 AC 123 ms
17,560 KB
testcase_35 AC 330 ms
33,968 KB
testcase_36 AC 4 ms
4,376 KB
testcase_37 AC 5 ms
4,376 KB
testcase_38 AC 4 ms
4,376 KB
testcase_39 AC 4 ms
4,376 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 446 ms
33,860 KB
testcase_42 AC 125 ms
12,692 KB
testcase_43 AC 225 ms
19,588 KB
testcase_44 AC 73 ms
9,220 KB
testcase_45 AC 219 ms
19,012 KB
testcase_46 AC 1 ms
4,376 KB
testcase_47 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
#include <cstdio>
#include <string>

using namespace std;

const long double inf = 1001001001001001001;

long double f(long double x1, long double y1, long double x2, long double y2) {
  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

int main() {
  cout << fixed << setprecision(15);
  int n, m;
  cin >> n >> m;
  int x, y;
  cin >> x >> y;
  x--;
  y--;
  vector<long double> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  vector<vector<pair<long double, int> > > g(n);
  for (int i = 0; i < m; i++) {
    int p, q;
    cin >> p >> q;
    p--;
    q--;
    g[p].push_back(make_pair(f(a[p], b[p], a[q], b[q]), q));
    g[q].push_back(make_pair(f(a[p], b[p], a[q], b[q]), p));
  }
  vector<long double> d(n, -inf);
  priority_queue<pair<long double, int>, vector<pair<long double, int> >, greater<pair<long double, int> > > pq;
  pq.push(make_pair(0, x));
  while (!pq.empty()) {
    long double cost = pq.top().first;
    int v = pq.top().second;
    pq.pop();
    if (d[v] == -inf) {
      d[v] = cost;
      for (auto p : g[v]) {
        long double cost2 = p.first;
        int v2 = p.second;
        if (d[v2] == -inf) {
          pq.push(make_pair(cost + cost2, v2));
        }
      }
    }
  }
  cout << d[y] << endl;
  return 0;
}
0