結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー tonyu0tonyu0
提出日時 2020-05-29 22:50:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 178 ms / 2,000 ms
コード長 1,622 bytes
コンパイル時間 1,703 ms
コンパイル使用メモリ 137,016 KB
実行使用メモリ 24,508 KB
最終ジャッジ日時 2024-04-27 03:14:03
合計ジャッジ時間 6,012 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 82 ms
13,160 KB
testcase_03 AC 118 ms
22,436 KB
testcase_04 AC 115 ms
23,180 KB
testcase_05 AC 94 ms
22,832 KB
testcase_06 AC 94 ms
24,508 KB
testcase_07 AC 32 ms
8,300 KB
testcase_08 AC 122 ms
21,788 KB
testcase_09 AC 13 ms
6,944 KB
testcase_10 AC 56 ms
11,752 KB
testcase_11 AC 38 ms
9,068 KB
testcase_12 AC 18 ms
7,296 KB
testcase_13 AC 82 ms
15,336 KB
testcase_14 AC 95 ms
18,536 KB
testcase_15 AC 111 ms
19,560 KB
testcase_16 AC 51 ms
11,500 KB
testcase_17 AC 124 ms
20,840 KB
testcase_18 AC 36 ms
9,448 KB
testcase_19 AC 116 ms
19,820 KB
testcase_20 AC 31 ms
8,164 KB
testcase_21 AC 41 ms
10,624 KB
testcase_22 AC 116 ms
19,304 KB
testcase_23 AC 3 ms
6,944 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 16 ms
6,944 KB
testcase_26 AC 60 ms
12,396 KB
testcase_27 AC 62 ms
12,780 KB
testcase_28 AC 106 ms
19,176 KB
testcase_29 AC 11 ms
6,940 KB
testcase_30 AC 111 ms
20,160 KB
testcase_31 AC 78 ms
15,848 KB
testcase_32 AC 50 ms
11,240 KB
testcase_33 AC 116 ms
21,668 KB
testcase_34 AC 39 ms
9,452 KB
testcase_35 AC 120 ms
20,324 KB
testcase_36 AC 2 ms
6,944 KB
testcase_37 AC 3 ms
6,944 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 3 ms
6,940 KB
testcase_40 AC 2 ms
6,940 KB
testcase_41 AC 178 ms
22,656 KB
testcase_42 AC 49 ms
9,448 KB
testcase_43 AC 87 ms
13,672 KB
testcase_44 AC 31 ms
7,272 KB
testcase_45 AC 84 ms
13,408 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <random>
#include <set>
#include <queue>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
constexpr ll INF = 1LL << 60;

int n, m, x, y;

// O(|V|+|E|)log|V|)
void dijkstra(int s, vector<vector<pair<int, double>>> &g, vector<double> &dist)
{
  using Info = pair<double, int>;
  // init
  dist.assign(g.size(), 1e18);
  dist[s] = 0.0;
  priority_queue<Info, vector<Info>, greater<Info>> pq;
  pq.emplace(0.0, s);
  //
  // main
  while (!pq.empty())
  {
    double d = pq.top().first;
    int v = pq.top().second;
    pq.pop();
    if (dist[v] < d)
      continue;
    for (auto e : g[v])
    {
      if (dist[e.first] > dist[v] + e.second)
      {
        dist[e.first] = dist[v] + e.second;
        pq.emplace(dist[e.first], e.first);
      }
    }
  }
  //
}

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

  cin >> n >> m >> x >> y;
  --x, --y;
  vector<pair<double, double>> pos;
  REP(i, n)
  {
    double p, q;
    cin >> p >> q;
    pos.emplace_back(p, q);
  }

  vector<vector<pair<int, double>>> g(n);
  REP(i, m)
  {
    int p, q;
    cin >> p >> q;
    --p, --q;
    double X = pos[p].first - pos[q].first;
    double Y = pos[p].second - pos[q].second;
    double cost = sqrt(X * X + Y * Y);
    g[q].emplace_back(p, cost);
    g[p].emplace_back(q, cost);
  }

  vector<double> dist;
  dijkstra(x, g, dist);
  cout << fixed << setprecision(10) << dist[y] << '\n';

  return 0;
}
0