結果
問題 | No.1065 電柱 / Pole (Easy) |
ユーザー | Haar |
提出日時 | 2020-05-29 21:51:22 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 419 ms / 2,000 ms |
コード長 | 3,761 bytes |
コンパイル時間 | 2,577 ms |
コンパイル使用メモリ | 222,840 KB |
実行使用メモリ | 24,044 KB |
最終ジャッジ日時 | 2024-11-06 03:51:04 |
合計ジャッジ時間 | 10,641 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 178 ms
14,080 KB |
testcase_03 | AC | 262 ms
23,468 KB |
testcase_04 | AC | 254 ms
22,516 KB |
testcase_05 | AC | 211 ms
22,472 KB |
testcase_06 | AC | 215 ms
22,572 KB |
testcase_07 | AC | 76 ms
8,576 KB |
testcase_08 | AC | 287 ms
23,268 KB |
testcase_09 | AC | 26 ms
6,820 KB |
testcase_10 | AC | 125 ms
12,416 KB |
testcase_11 | AC | 88 ms
9,600 KB |
testcase_12 | AC | 48 ms
7,168 KB |
testcase_13 | AC | 177 ms
15,120 KB |
testcase_14 | AC | 210 ms
17,700 KB |
testcase_15 | AC | 251 ms
19,480 KB |
testcase_16 | AC | 114 ms
11,704 KB |
testcase_17 | AC | 263 ms
20,832 KB |
testcase_18 | AC | 79 ms
9,344 KB |
testcase_19 | AC | 253 ms
20,132 KB |
testcase_20 | AC | 65 ms
7,936 KB |
testcase_21 | AC | 97 ms
10,880 KB |
testcase_22 | AC | 228 ms
18,496 KB |
testcase_23 | AC | 4 ms
6,816 KB |
testcase_24 | AC | 4 ms
6,820 KB |
testcase_25 | AC | 44 ms
6,912 KB |
testcase_26 | AC | 136 ms
12,968 KB |
testcase_27 | AC | 130 ms
12,640 KB |
testcase_28 | AC | 221 ms
18,916 KB |
testcase_29 | AC | 26 ms
6,820 KB |
testcase_30 | AC | 237 ms
20,656 KB |
testcase_31 | AC | 168 ms
16,676 KB |
testcase_32 | AC | 114 ms
11,556 KB |
testcase_33 | AC | 239 ms
21,628 KB |
testcase_34 | AC | 84 ms
9,600 KB |
testcase_35 | AC | 267 ms
20,832 KB |
testcase_36 | AC | 4 ms
6,820 KB |
testcase_37 | AC | 5 ms
6,820 KB |
testcase_38 | AC | 4 ms
6,820 KB |
testcase_39 | AC | 5 ms
6,820 KB |
testcase_40 | AC | 3 ms
6,820 KB |
testcase_41 | AC | 419 ms
24,044 KB |
testcase_42 | AC | 107 ms
9,728 KB |
testcase_43 | AC | 194 ms
14,336 KB |
testcase_44 | AC | 64 ms
7,424 KB |
testcase_45 | AC | 190 ms
14,080 KB |
testcase_46 | AC | 2 ms
6,816 KB |
testcase_47 | AC | 2 ms
6,816 KB |
ソースコード
#include <bits/stdc++.h> /** * @title グラフ用テンプレート * @docs graph_template.md */ template <typename Cost = int> class Edge{ public: int from,to; Cost cost; Edge() {} Edge(int to, Cost cost): to(to), cost(cost){} Edge(int from, int to, Cost cost): from(from), to(to), cost(cost){} }; template <typename T> using Graph = std::vector<std::vector<Edge<T>>>; template <typename T> using Tree = std::vector<std::vector<Edge<T>>>; template <typename T, typename C> void add_edge(C &g, int from, int to, T w = 1){ g[from].emplace_back(from, to, w); } template <typename T, typename C> void add_undirected(C &g, int a, int b, T w = 1){ add_edge<T, C>(g, a, b, w); add_edge<T, C>(g, b, a, w); } /** * @docs input_graph.md */ template <typename T, size_t I, bool WEIGHTED> std::vector<Edge<T>> input_edges(int M){ std::vector<Edge<T>> ret; for(int i = 0; i < M; ++i){ int s, t; std::cin >> s >> t; s -= I; t -= I; T w = 1; if(WEIGHTED) std::cin >> w; ret.emplace_back(s, t, w); } return ret; } template <typename T, bool DIRECTED> Graph<T> convert_to_graph(int N, const std::vector<Edge<T>> &edges){ Graph<T> g(N); for(const auto &e : edges){ add_edge(g, e.from, e.to, e.cost); if(not DIRECTED) add_edge(g, e.to, e.from, e.cost); } return g; } /** * @docs input_tuple_vector.md */ template <typename T, size_t ... I> void input_tuple_vector_init(T &val, int N, std::index_sequence<I...>){ (void)std::initializer_list<int>{ (void(std::get<I>(val).resize(N)), 0)... }; } template <typename T, size_t ... I> void input_tuple_vector_helper(T &val, int i, std::index_sequence<I...>){ (void)std::initializer_list<int>{ (void(std::cin >> std::get<I>(val)[i]), 0)... }; } template <typename ... Args> auto input_tuple_vector(int N){ std::tuple<std::vector<Args>...> ret; input_tuple_vector_init(ret, N, std::make_index_sequence<sizeof...(Args)>()); for(int i = 0; i < N; ++i){ input_tuple_vector_helper(ret, i, std::make_index_sequence<sizeof...(Args)>()); } return ret; } /** * @title Dijkstra法 * @docs dijkstra.md */ template <typename T> class Dijkstra{ public: std::vector<std::optional<T>> dist; private: void run(const Graph<T> &graph, std::vector<int> src){ const int n = graph.size(); dist.assign(n, std::nullopt); std::vector<bool> check(n, false); std::priority_queue<std::pair<T,int>, std::vector<std::pair<T,int>>, std::greater<std::pair<T,int>>> pq; for(auto s : src){ dist[s] = 0; pq.emplace(0, s); } while(not pq.empty()){ const auto [d,i] = pq.top(); pq.pop(); if(check[i]) continue; check[i] = true; for(auto &e : graph[i]){ if(not dist[e.to]){ dist[e.to] = d + e.cost; pq.emplace(*dist[e.to], e.to); }else{ if(*dist[e.to] > d + e.cost){ dist[e.to] = d + e.cost; if(not check[e.to]) pq.emplace(*dist[e.to], e.to); } } } } } public: Dijkstra(const Graph<T> &graph, int src){run(graph, {src});} Dijkstra(const Graph<T> &graph, const std::vector<int> &src){run(graph, src);} }; int main(){ int N, M, X, Y; while(std::cin >> N >> M >> X >> Y){ --X, --Y; auto [p, q] = input_tuple_vector<double, double>(N); Graph<double> g(N); for(int i = 0; i < M; ++i){ int P, Q; std::cin >> P >> Q; --P, --Q; double dx = p[P] - p[Q]; double dy = q[P] - q[Q]; double L = std::sqrt(dx * dx + dy * dy); add_undirected(g, P, Q, L); } auto ans = Dijkstra(g, X).dist[Y].value(); std::cout << std::fixed << std::setprecision(12) << ans << "\n"; } return 0; }