結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー 0w1
提出日時 2020-11-15 17:16:09
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 431 ms / 2,000 ms
コード長 882 bytes
コンパイル時間 3,876 ms
コンパイル使用メモリ 206,948 KB
最終ジャッジ日時 2025-01-16 00:59:04
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);

  int N, M; { cin >> N >> M; }
  int Gx, Gy; { cin >> Gx >> Gy; --Gx, --Gy; }
  vector<int> X(N), Y(N); { for (int i = 0; i < N; ++i) cin >> X[i] >> Y[i]; }
  vector<vector<int>> G(N); {
    for (int i = 0; i < M; ++i) {
      int P, Q; { cin >> P >> Q; --P, --Q; }
      G[P].push_back(Q);
      G[Q].push_back(P);
    }
  }

  vector<double> dis(N, 1e20); {
    set<tuple<double, int>> bag;
    bag.emplace(dis[Gx] = 0, Gx);
    while (bag.size()) {
      double d;
      int u;
      tie(d, u) = *bag.begin();
      bag.erase(bag.begin());
      if (d != dis[u]) continue;
      for (int v : G[u]) {
        double nd = d + hypot(X[u] - X[v], Y[u] - Y[v]);
        if (nd < dis[v]) bag.emplace(dis[v] = nd, v);
      }
    }
  }

  cout << fixed << setprecision(9) << dis[Gy] << endl;
}
0