結果
| 問題 |
No.1065 電柱 / Pole (Easy)
|
| コンテスト | |
| ユーザー |
🍮かんプリン
|
| 提出日時 | 2020-05-29 21:50:25 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 364 ms / 2,000 ms |
| コード長 | 2,004 bytes |
| コンパイル時間 | 2,439 ms |
| コンパイル使用メモリ | 175,044 KB |
| 実行使用メモリ | 21,416 KB |
| 最終ジャッジ日時 | 2024-11-06 03:48:31 |
| 合計ジャッジ時間 | 10,075 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 46 |
ソースコード
/**
* @FileName b.cpp
* @Author kanpurin
* @Created 2020.05.29 21:50:20
**/
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// dijkstra O(ElogV)
// verify : https://onlinejudge.u-aizu.ac.jp/problems/GRL_1_A
// ※拡張ダイクストラ
template<typename T>
struct Dijkstra {
private:
int V;
struct edge { int to; T cost; };
vector<vector<edge>> G;
public:
const T inf = numeric_limits<T>::max();
// s から i の最小コスト
// 経路がない場合は inf
vector<T> d; // (頂点) ※
Dijkstra(int V) : V(V) {
G.resize(V);
}
// 辺の追加
// 有向の場合 directed = true
void add_edge(int from, int to, T weight, bool directed = false) {
G[from].push_back({to,weight});
if (!directed) G[to].push_back({from,weight});
}
void build(int s) {
d.assign(V, inf); // ※
typedef tuple<T, int> P; //(距離,頂点) ※
priority_queue<P, vector<P>, greater<P>> pq;
d[s] = 0; // ※
pq.push(P(d[s], s)); // ※
while (!pq.empty()) {
P p = pq.top(); pq.pop();
int v = get<1>(p);
// ※
if (d[v] < get<0>(p)) continue; // ※
for (const edge &e : G[v])
{
// ※
if (d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
pq.push(P(d[e.to], e.to));
}
}
}
}
};
int main() {
int n,m;cin >> n >> m;
int s,t;cin >> s >> t;
s--;t--;
Dijkstra<double> g(n);
vector<pair<int,int>> p(n);
for (int i = 0; i < n; i++) {
cin >> p[i].first >> p[i].second;
}
for (int i = 0; i < m; i++) {
int u,v;cin >> u >> v;
u--;v--;
g.add_edge(u,v,sqrt((p[u].first-p[v].first)*(p[u].first-p[v].first)+(p[u].second-p[v].second)*(p[u].second-p[v].second)));
}
g.build(s);
printf("%.10f\n",g.d[t]);
return 0;
}
🍮かんプリン