結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー SSRSSSRS
提出日時 2020-11-06 20:47:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 297 ms / 2,000 ms
コード長 963 bytes
コンパイル時間 1,593 ms
コンパイル使用メモリ 175,564 KB
実行使用メモリ 24,900 KB
最終ジャッジ日時 2023-09-29 17:58:11
合計ジャッジ時間 9,457 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 132 ms
12,348 KB
testcase_03 AC 230 ms
24,048 KB
testcase_04 AC 222 ms
24,140 KB
testcase_05 AC 187 ms
24,900 KB
testcase_06 AC 187 ms
23,300 KB
testcase_07 AC 59 ms
7,832 KB
testcase_08 AC 225 ms
19,900 KB
testcase_09 AC 20 ms
4,736 KB
testcase_10 AC 100 ms
10,892 KB
testcase_11 AC 68 ms
8,044 KB
testcase_12 AC 63 ms
9,044 KB
testcase_13 AC 155 ms
14,680 KB
testcase_14 AC 167 ms
15,612 KB
testcase_15 AC 202 ms
20,996 KB
testcase_16 AC 112 ms
11,956 KB
testcase_17 AC 226 ms
18,324 KB
testcase_18 AC 84 ms
10,124 KB
testcase_19 AC 198 ms
17,756 KB
testcase_20 AC 55 ms
7,468 KB
testcase_21 AC 106 ms
11,716 KB
testcase_22 AC 191 ms
16,368 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 AC 4 ms
4,380 KB
testcase_25 AC 57 ms
7,624 KB
testcase_26 AC 113 ms
12,184 KB
testcase_27 AC 121 ms
12,640 KB
testcase_28 AC 207 ms
19,704 KB
testcase_29 AC 31 ms
5,900 KB
testcase_30 AC 218 ms
20,920 KB
testcase_31 AC 138 ms
14,988 KB
testcase_32 AC 90 ms
10,652 KB
testcase_33 AC 205 ms
20,452 KB
testcase_34 AC 85 ms
10,520 KB
testcase_35 AC 211 ms
18,856 KB
testcase_36 AC 3 ms
4,380 KB
testcase_37 AC 4 ms
4,380 KB
testcase_38 AC 3 ms
4,376 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 2 ms
4,384 KB
testcase_41 AC 297 ms
20,724 KB
testcase_42 AC 81 ms
8,760 KB
testcase_43 AC 147 ms
12,400 KB
testcase_44 AC 50 ms
6,460 KB
testcase_45 AC 139 ms
12,012 KB
testcase_46 AC 1 ms
4,380 KB
testcase_47 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  cout << fixed << setprecision(5);
  int N, M;
  cin >> N >> M;
  int X, Y;
  cin >> X >> Y;
  X--;
  Y--;
  vector<int> p(N), q(N);
  for (int i = 0; i < N; i++){
    cin >> p[i] >> q[i];
  }
  vector<vector<pair<double, int>>> E(N);
  for (int i = 0; i < M; i++){
    int P, Q;
    cin >> P >> Q;
    P--;
    Q--;
    double d = hypot(p[Q] - p[P], q[Q] - q[P]);
    E[P].push_back(make_pair(d, Q));
    E[Q].push_back(make_pair(d, P));
  }
  vector<double> d(N, -1);
  priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> pq;
  pq.push(make_pair(0, X));
  while (!pq.empty()){
    double c = pq.top().first;
    int v = pq.top().second;
    pq.pop();
    if (d[v] == -1){
      d[v] = c;
      for (auto P : E[v]){
        int w = P.second;
        if (d[w] == -1){
          pq.push(make_pair(c + P.first, w));
        }
      }
    }
  }
  cout << d[Y] << endl;
}
0