結果
| 問題 |
No.1065 電柱 / Pole (Easy)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-29 21:39:22 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 324 ms / 2,000 ms |
| コード長 | 1,634 bytes |
| コンパイル時間 | 1,597 ms |
| コンパイル使用メモリ | 111,576 KB |
| 最終ジャッジ日時 | 2025-01-10 16:43:12 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 46 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:53:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
53 | scanf("%d %d", &p[i], &q[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
main.cpp:58:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
58 | scanf("%d %d", &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;
template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;
template <typename T>
struct edge {
int from, to; T cost;
edge(int to, T cost) : from(-1), to(to), cost(cost) {}
edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
};
template <typename T>
vector<T> dijkstra(int s,vector<vector<edge<T>>> &G){
auto n = G.size();
vector<T> d(n, INF<T>);
priority_queue<pair<T, int>,vector<pair<T, int>>,greater<>> Q;
d[s] = 0;
Q.emplace(0, s);
while(!Q.empty()){
T cost; int i;
tie(cost, i) = Q.top(); Q.pop();
if(d[i] < cost) continue;
for (auto &&e : G[i]) {
auto cost2 = cost + e.cost;
if(d[e.to] <= cost2) continue;
d[e.to] = cost2;
Q.emplace(d[e.to], e.to);
}
}
return d;
}
int main() {
int n, m, x, y;
cin >> n >> m >> x >> y;
x--; y--;
vector<int> p(n), q(n);
for (int i = 0; i < n; ++i) {
scanf("%d %d", &p[i], &q[i]);
}
vector<vector<edge<double>>> G(n);
for (int i = 0; i < m; ++i) {
int a, b;
scanf("%d %d", &a, &b);
a--; b--;
G[a].emplace_back(b, hypot(p[a]-p[b], q[a]-q[b]));
G[b].emplace_back(a, hypot(p[a]-p[b], q[a]-q[b]));
}
printf("%.10lf\n", dijkstra(x, G)[y]);
return 0;
}