結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー 👑 jupirojupiro
提出日時 2020-06-04 17:16:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 172 ms / 2,000 ms
コード長 2,184 bytes
コンパイル時間 1,472 ms
コンパイル使用メモリ 143,952 KB
実行使用メモリ 20,992 KB
最終ジャッジ日時 2024-05-07 02:30:42
合計ジャッジ時間 8,108 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 77 ms
12,416 KB
testcase_03 AC 106 ms
20,028 KB
testcase_04 AC 108 ms
20,032 KB
testcase_05 AC 88 ms
19,904 KB
testcase_06 AC 91 ms
19,908 KB
testcase_07 AC 25 ms
7,936 KB
testcase_08 AC 99 ms
20,352 KB
testcase_09 AC 11 ms
5,376 KB
testcase_10 AC 42 ms
11,008 KB
testcase_11 AC 31 ms
8,704 KB
testcase_12 AC 20 ms
7,168 KB
testcase_13 AC 73 ms
13,888 KB
testcase_14 AC 89 ms
16,060 KB
testcase_15 AC 105 ms
17,520 KB
testcase_16 AC 53 ms
11,204 KB
testcase_17 AC 116 ms
18,652 KB
testcase_18 AC 38 ms
8,832 KB
testcase_19 AC 110 ms
17,884 KB
testcase_20 AC 27 ms
7,320 KB
testcase_21 AC 45 ms
10,368 KB
testcase_22 AC 99 ms
16,836 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 17 ms
6,944 KB
testcase_26 AC 57 ms
11,820 KB
testcase_27 AC 56 ms
11,892 KB
testcase_28 AC 102 ms
17,412 KB
testcase_29 AC 13 ms
6,016 KB
testcase_30 AC 110 ms
18,688 KB
testcase_31 AC 73 ms
15,056 KB
testcase_32 AC 44 ms
10,728 KB
testcase_33 AC 106 ms
19,216 KB
testcase_34 AC 40 ms
8,960 KB
testcase_35 AC 121 ms
18,892 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 3 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 172 ms
20,992 KB
testcase_42 AC 42 ms
8,960 KB
testcase_43 AC 77 ms
12,800 KB
testcase_44 AC 26 ms
6,912 KB
testcase_45 AC 75 ms
12,416 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0