結果
問題 | No.1065 電柱 / Pole (Easy) |
ユーザー |
|
提出日時 | 2020-06-04 17:16:04 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 286 ms / 2,000 ms |
コード長 | 2,184 bytes |
コンパイル時間 | 2,356 ms |
コンパイル使用メモリ | 139,332 KB |
最終ジャッジ日時 | 2025-01-10 21:14:44 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 46 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:61:24: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 61 | int n, m; scanf("%d %d", &n, &m); | ~~~~~^~~~~~~~~~~~~~~~~ main.cpp:62:24: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 62 | int x, y; scanf("%d %d", &x, &y); x--; y--; | ~~~~~^~~~~~~~~~~~~~~~~ main.cpp:65:42: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 65 | for (int i = 0; i < n; i++) scanf("%d %d", &vp[i].first, &vp[i].second); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ main.cpp:67:32: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 67 | int u, v; scanf("%d %d", &u, &v); | ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
#include <cstdio> #include <iostream> #include <string> #include <sstream> #include <stack> #include <algorithm> #include <cmath> #include <queue> #include <map> #include <set> #include <cstdlib> #include <bitset> #include <tuple> #include <assert.h> #include <deque> #include <bitset> #include <iomanip> #include <limits> #include <chrono> #include <random> #include <array> #include <unordered_map> #include <functional> #include <complex> #include <numeric> template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } constexpr long long MAX = 5100000; constexpr long long INF = 1LL << 60; constexpr int inf = 1000000007; //constexpr long long mod = 1000000007LL; constexpr long long mod = 998244353LL; const long double PI = acos((long double)(-1)); using namespace std; typedef unsigned long long ull; typedef long long ll; vector<double> dijkstra(int start, vector<vector<pair<int, double>>>& graph) { vector<double> dist(graph.size(), INF); dist[start] = 0; priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> pq; pq.emplace(0, start); while (!pq.empty()) { double cost; int idx; tie(cost, idx) = pq.top(); pq.pop(); if (dist[idx] < cost) continue; for (auto next : graph[idx]) if (chmin(dist[next.first], cost + next.second)) pq.emplace(dist[next.first], next.first); } return dist; } using P = pair<int, int>; double dist(P a, P b) { double dx = a.first - b.first; double dy = a.second - b.second; return sqrt(dx * dx + dy * dy); } int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ int n, m; scanf("%d %d", &n, &m); int x, y; scanf("%d %d", &x, &y); x--; y--; vector<vector<pair<int, double>>> g(n); vector<P> vp(n); for (int i = 0; i < n; i++) scanf("%d %d", &vp[i].first, &vp[i].second); for (int i = 0; i < m; i++) { int u, v; scanf("%d %d", &u, &v); u--; v--; g[u].emplace_back(v, dist(vp[u], vp[v])); g[v].emplace_back(u, dist(vp[u], vp[v])); } auto dist = dijkstra(x, g); cout << fixed << setprecision(12) << dist[y] << endl; return 0; }