結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー FF256grhyFF256grhy
提出日時 2023-08-23 18:18:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 320 ms / 2,000 ms
コード長 2,949 bytes
コンパイル時間 2,257 ms
コンパイル使用メモリ 211,108 KB
実行使用メモリ 20,916 KB
最終ジャッジ日時 2023-08-23 18:18:16
合計ジャッジ時間 12,281 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 144 ms
12,148 KB
testcase_03 AC 218 ms
19,960 KB
testcase_04 AC 216 ms
20,140 KB
testcase_05 AC 175 ms
20,160 KB
testcase_06 AC 174 ms
20,916 KB
testcase_07 AC 59 ms
7,544 KB
testcase_08 AC 224 ms
19,968 KB
testcase_09 AC 20 ms
4,648 KB
testcase_10 AC 99 ms
10,396 KB
testcase_11 AC 68 ms
8,536 KB
testcase_12 AC 46 ms
6,752 KB
testcase_13 AC 150 ms
13,576 KB
testcase_14 AC 191 ms
15,788 KB
testcase_15 AC 204 ms
17,376 KB
testcase_16 AC 98 ms
10,880 KB
testcase_17 AC 223 ms
18,648 KB
testcase_18 AC 71 ms
8,776 KB
testcase_19 AC 206 ms
17,652 KB
testcase_20 AC 53 ms
7,408 KB
testcase_21 AC 95 ms
10,200 KB
testcase_22 AC 181 ms
16,424 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 4 ms
4,380 KB
testcase_25 AC 40 ms
6,548 KB
testcase_26 AC 107 ms
11,528 KB
testcase_27 AC 112 ms
11,476 KB
testcase_28 AC 186 ms
17,124 KB
testcase_29 AC 24 ms
5,868 KB
testcase_30 AC 192 ms
18,492 KB
testcase_31 AC 131 ms
15,096 KB
testcase_32 AC 91 ms
10,476 KB
testcase_33 AC 194 ms
20,336 KB
testcase_34 AC 73 ms
9,108 KB
testcase_35 AC 209 ms
18,712 KB
testcase_36 AC 3 ms
4,380 KB
testcase_37 AC 3 ms
4,376 KB
testcase_38 AC 3 ms
4,376 KB
testcase_39 AC 3 ms
4,380 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 320 ms
20,680 KB
testcase_42 AC 93 ms
8,596 KB
testcase_43 AC 149 ms
12,356 KB
testcase_44 AC 50 ms
6,648 KB
testcase_45 AC 141 ms
11,980 KB
testcase_46 AC 1 ms
4,384 KB
testcase_47 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)

template<typename T, typename U> istream & operator>>(istream & s, pair<T, U> & p) { return (s >> p.FI >> p.SE); }
template<typename T, typename U> ostream & operator<<(ostream & s, pair<T, U> const & p) { return (s << p.FI << " " << p.SE); }

template<typename T> istream & operator>>(istream & s, vector<T> & v) { RF(e, v) { s >> e; } return s; }
template<typename T> ostream & operator<<(ostream & s, vector<T> const & v) {
	inc(i, SI(v)) { s << (i == 0 ? "" : " ") << v[i]; }
	return s;
}

#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T &  a, U &  ... b) { cin >> a; IN_(b ...); };
template<typename T                > void OUT(T && a            ) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

template<typename T> using LPQ = priority_queue<T, vector<T>, greater<T>>;
template<typename C> void dijkstra(int s, vector<vector<pair<int, C>>> const & g, vector<C> & d) {
	LPQ<pair<C, int>> q;
	d[s] = 0;
	q.emplace(d[s], s);
	while(! q.empty()) {
		C   c = q.top().FI;
		int v = q.top().SE;
		q.pop();
		if(d[v] != c) { continue; }
		for(auto & e : g[v]) {
			int ev = e.FI;
			C   ec = e.SE;
			if(setmin(d[ev], d[v] + ec)) { q.emplace(d[ev], ev); }
		}
	}
}

int main() {
	IN(int, n, m, x, y);
	x--; y--;
	vector<pair<int, int>> p(n);
	cin >> p;
	vector<vector<pair<int, double>>> g(n);
	inc(i, m) {
		IN(int, a, b);
		a--; b--;
		double d = hypot(p[a].FI - p[b].FI, p[a].SE - p[b].SE);
		g[a].EB(b, d);
		g[b].EB(a, d);
	}
	const double INF = 1e9;
	vector<double> d(n, INF);
	dijkstra(x, g, d);
	OUT(d[y]);
}
0