結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー mmn15277198mmn15277198
提出日時 2022-05-02 20:52:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 463 ms / 2,000 ms
コード長 1,421 bytes
コンパイル時間 1,354 ms
コンパイル使用メモリ 101,800 KB
実行使用メモリ 39,640 KB
最終ジャッジ日時 2023-09-14 17:55:05
合計ジャッジ時間 12,137 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 212 ms
18,888 KB
testcase_03 AC 319 ms
39,500 KB
testcase_04 AC 316 ms
39,580 KB
testcase_05 AC 242 ms
39,584 KB
testcase_06 AC 245 ms
39,640 KB
testcase_07 AC 77 ms
10,748 KB
testcase_08 AC 291 ms
32,372 KB
testcase_09 AC 26 ms
5,792 KB
testcase_10 AC 128 ms
16,156 KB
testcase_11 AC 88 ms
12,116 KB
testcase_12 AC 80 ms
14,768 KB
testcase_13 AC 241 ms
24,372 KB
testcase_14 AC 271 ms
26,064 KB
testcase_15 AC 311 ms
32,880 KB
testcase_16 AC 159 ms
19,608 KB
testcase_17 AC 337 ms
31,064 KB
testcase_18 AC 114 ms
16,920 KB
testcase_19 AC 316 ms
29,400 KB
testcase_20 AC 83 ms
10,740 KB
testcase_21 AC 144 ms
19,668 KB
testcase_22 AC 292 ms
27,276 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 6 ms
4,376 KB
testcase_25 AC 70 ms
12,240 KB
testcase_26 AC 178 ms
20,008 KB
testcase_27 AC 184 ms
20,660 KB
testcase_28 AC 310 ms
33,100 KB
testcase_29 AC 38 ms
8,376 KB
testcase_30 AC 319 ms
37,364 KB
testcase_31 AC 212 ms
24,820 KB
testcase_32 AC 137 ms
16,328 KB
testcase_33 AC 301 ms
32,352 KB
testcase_34 AC 120 ms
16,600 KB
testcase_35 AC 332 ms
31,712 KB
testcase_36 AC 3 ms
4,376 KB
testcase_37 AC 5 ms
4,376 KB
testcase_38 AC 3 ms
4,380 KB
testcase_39 AC 5 ms
4,376 KB
testcase_40 AC 3 ms
4,380 KB
testcase_41 AC 463 ms
33,952 KB
testcase_42 AC 122 ms
12,780 KB
testcase_43 AC 225 ms
19,520 KB
testcase_44 AC 73 ms
9,284 KB
testcase_45 AC 216 ms
19,212 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 2 ms
4,376 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;

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

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, -1);
  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] == -1) {
      d[v] = cost;
      for (auto p : g[v]) {
        long double cost2 = p.first;
        int v2 = p.second;
        if (d[v2] == -1) {
          pq.push(make_pair(cost + cost2, v2));
        }
      } 
    }
  }
  cout << d[y] << endl;
  return 0;
}
0