結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー betit0919betit0919
提出日時 2020-05-29 21:47:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 321 ms / 2,000 ms
コード長 2,124 bytes
コンパイル時間 1,411 ms
コンパイル使用メモリ 130,980 KB
実行使用メモリ 34,176 KB
最終ジャッジ日時 2024-04-23 21:12:09
合計ジャッジ時間 7,787 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 146 ms
19,072 KB
testcase_03 AC 177 ms
33,976 KB
testcase_04 AC 177 ms
33,584 KB
testcase_05 AC 134 ms
33,464 KB
testcase_06 AC 133 ms
33,460 KB
testcase_07 AC 42 ms
11,392 KB
testcase_08 AC 156 ms
32,512 KB
testcase_09 AC 15 ms
6,016 KB
testcase_10 AC 69 ms
16,512 KB
testcase_11 AC 48 ms
12,544 KB
testcase_12 AC 25 ms
10,880 KB
testcase_13 AC 143 ms
22,428 KB
testcase_14 AC 176 ms
26,300 KB
testcase_15 AC 208 ms
29,024 KB
testcase_16 AC 90 ms
17,808 KB
testcase_17 AC 224 ms
31,156 KB
testcase_18 AC 54 ms
14,040 KB
testcase_19 AC 203 ms
29,524 KB
testcase_20 AC 46 ms
10,520 KB
testcase_21 AC 70 ms
16,848 KB
testcase_22 AC 200 ms
27,656 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 24 ms
10,496 KB
testcase_26 AC 106 ms
19,092 KB
testcase_27 AC 106 ms
18,848 KB
testcase_28 AC 190 ms
29,172 KB
testcase_29 AC 17 ms
8,192 KB
testcase_30 AC 212 ms
31,912 KB
testcase_31 AC 139 ms
24,860 KB
testcase_32 AC 87 ms
16,596 KB
testcase_33 AC 216 ms
32,352 KB
testcase_34 AC 62 ms
13,908 KB
testcase_35 AC 209 ms
32,008 KB
testcase_36 AC 3 ms
5,376 KB
testcase_37 AC 3 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 321 ms
34,176 KB
testcase_42 AC 74 ms
13,056 KB
testcase_43 AC 153 ms
19,712 KB
testcase_44 AC 42 ms
9,472 KB
testcase_45 AC 144 ms
19,456 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

template<class T>
struct Edge {
  int to;
  T cost;
  Edge() {}
  Edge(int to, T cost) : to(to), cost(cost) {}
  bool operator>(const Edge &r) const { return this->cost > r.cost; }
};

template<class T>
vector<T> Dijkstra(const vector<vector<Edge<T>>> &edges, const int st) {

  const int V = (int)edges.size();
  const T inf = numeric_limits<T>::max() / 2;
  vector<T> cost(V, inf);
  cost[st] = 0;

  priority_queue<Edge<T>, vector<Edge<T>>, greater<Edge<T>>> pq;
  pq.emplace(st, cost[st]);

  while (!pq.empty()) {

    Edge<T> now(pq.top().to, pq.top().cost);
    pq.pop();

    if (cost[now.to] < now.cost) continue;
    for (const Edge<T> &e : edges[now.to]) {
      T tmp_cost = now.cost + e.cost;
      if (cost[e.to] > tmp_cost) {
        cost[e.to] = tmp_cost;
        pq.emplace(e.to, cost[e.to]);
      }
    }
  }

  return cost;
}

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;
}


int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int N,M,X,Y;
  cin>>N>>M>>X>>Y;
  X--;Y--;

  vector<long double>p(N),q(N);
  REP(i,N){
    cin>>p[i]>>q[i];
  }
  vector<vector<Edge<long double>>> edges(N);

  REP(i,M){
    int P,Q;
    cin>>P>>Q;
    P--;Q--;
    long double len=sqrtl((p[P]-p[Q])*(p[P]-p[Q]) + (q[P]-q[Q])*(q[P]-q[Q]));
    edges[P].emplace_back(Q,len);
    edges[Q].emplace_back(P,len);
  }

  auto ans = Dijkstra<long double>(edges,X);

  cout<<setprecision(15)<<ans[Y]<<endl;
}
0