結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー bond_cmprogbond_cmprog
提出日時 2020-05-29 21:53:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 223 ms / 2,000 ms
コード長 2,101 bytes
コンパイル時間 2,154 ms
コンパイル使用メモリ 203,400 KB
実行使用メモリ 22,528 KB
最終ジャッジ日時 2024-04-23 21:52:03
合計ジャッジ時間 6,824 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 90 ms
13,184 KB
testcase_03 AC 131 ms
21,508 KB
testcase_04 AC 137 ms
21,124 KB
testcase_05 AC 100 ms
20,992 KB
testcase_06 AC 100 ms
20,992 KB
testcase_07 AC 34 ms
8,320 KB
testcase_08 AC 128 ms
21,892 KB
testcase_09 AC 13 ms
5,376 KB
testcase_10 AC 58 ms
11,648 KB
testcase_11 AC 38 ms
9,088 KB
testcase_12 AC 20 ms
7,296 KB
testcase_13 AC 88 ms
14,456 KB
testcase_14 AC 118 ms
16,980 KB
testcase_15 AC 130 ms
18,572 KB
testcase_16 AC 58 ms
11,476 KB
testcase_17 AC 137 ms
19,880 KB
testcase_18 AC 43 ms
9,216 KB
testcase_19 AC 148 ms
19,028 KB
testcase_20 AC 33 ms
7,936 KB
testcase_21 AC 48 ms
10,624 KB
testcase_22 AC 120 ms
17,684 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 20 ms
7,040 KB
testcase_26 AC 66 ms
12,480 KB
testcase_27 AC 65 ms
12,324 KB
testcase_28 AC 118 ms
18,024 KB
testcase_29 AC 14 ms
6,272 KB
testcase_30 AC 128 ms
19,692 KB
testcase_31 AC 91 ms
16,008 KB
testcase_32 AC 60 ms
11,160 KB
testcase_33 AC 130 ms
20,432 KB
testcase_34 AC 45 ms
9,344 KB
testcase_35 AC 132 ms
19,984 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 223 ms
22,528 KB
testcase_42 AC 53 ms
9,472 KB
testcase_43 AC 99 ms
13,568 KB
testcase_44 AC 34 ms
7,040 KB
testcase_45 AC 93 ms
13,312 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
//const ll MOD = 1000000007;
const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<class T> class Dijkstra {
public:
	int N;
	T inf;
	vector<T> cost;
	vector<vector<pair<T, int>>> edge;

	Dijkstra(const int N, T inf) : N(N), inf(inf),cost(N), edge(N) {
	}

	void make_edge(int from, int to, T w) {
		edge[from].push_back({ w,to });
	}

	void solve(int start) {
		for(int i = 0; i < N; ++i) cost[i] = inf;

		priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> pq;
		cost[start] = 0;
		pq.push({ 0,start });

		while (!pq.empty()) {
			T v = pq.top().first;
			int from = pq.top().second;
			pq.pop();
			for (auto u : edge[from]) {
				T w = v + u.first;
				int to = u.second;
				if (w < cost[to]) {
					cost[to] = w;
					pq.push({ w,to });
				}
			}
		}
		return;
	}
};

void solve(){
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    --X, --Y;
    Dijkstra<double> dijk(N, LINF);
    vector<double> p(N), q(N);
    REP(i,N) cin >> p[i] >> q[i];
    REP(i,M){
        int P, Q;
        cin >> P >> Q;
        --P, --Q;
        double cost = hypot(abs(p[P] - p[Q]), abs(q[P] - q[Q]));
        dijk.make_edge(P, Q, cost);
        dijk.make_edge(Q, P, cost);
    }
    dijk.solve(X);
    printf("%.12lf\n", dijk.cost[Y]);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}
0