結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー Moss_LocalMoss_Local
提出日時 2020-05-30 06:45:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 230 ms / 2,000 ms
コード長 3,463 bytes
コンパイル時間 1,559 ms
コンパイル使用メモリ 134,792 KB
実行使用メモリ 25,320 KB
最終ジャッジ日時 2024-04-24 15:51:39
合計ジャッジ時間 8,054 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 112 ms
14,692 KB
testcase_03 AC 152 ms
23,940 KB
testcase_04 AC 147 ms
24,068 KB
testcase_05 AC 117 ms
23,808 KB
testcase_06 AC 119 ms
23,808 KB
testcase_07 AC 39 ms
9,192 KB
testcase_08 AC 144 ms
24,932 KB
testcase_09 AC 14 ms
5,376 KB
testcase_10 AC 66 ms
13,156 KB
testcase_11 AC 45 ms
10,208 KB
testcase_12 AC 21 ms
9,216 KB
testcase_13 AC 111 ms
17,764 KB
testcase_14 AC 126 ms
20,452 KB
testcase_15 AC 138 ms
22,112 KB
testcase_16 AC 64 ms
14,028 KB
testcase_17 AC 155 ms
23,652 KB
testcase_18 AC 42 ms
11,492 KB
testcase_19 AC 134 ms
22,112 KB
testcase_20 AC 36 ms
8,676 KB
testcase_21 AC 50 ms
13,440 KB
testcase_22 AC 131 ms
21,860 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 19 ms
8,832 KB
testcase_26 AC 76 ms
14,108 KB
testcase_27 AC 74 ms
14,948 KB
testcase_28 AC 125 ms
22,628 KB
testcase_29 AC 14 ms
7,168 KB
testcase_30 AC 135 ms
22,304 KB
testcase_31 AC 91 ms
17,452 KB
testcase_32 AC 59 ms
12,388 KB
testcase_33 AC 136 ms
24,040 KB
testcase_34 AC 48 ms
11,112 KB
testcase_35 AC 146 ms
22,912 KB
testcase_36 AC 3 ms
5,376 KB
testcase_37 AC 3 ms
5,376 KB
testcase_38 AC 3 ms
5,376 KB
testcase_39 AC 3 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 230 ms
25,320 KB
testcase_42 AC 57 ms
10,340 KB
testcase_43 AC 101 ms
15,076 KB
testcase_44 AC 36 ms
7,780 KB
testcase_45 AC 99 ms
14,820 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
#include<assert.h>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T >
struct edge {
  int src, to;
  T cost;
 
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
 
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
 
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
 
  operator int() const { return to; }
};
 
template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;
 
template< typename T >
vector< T > dijkstra(WeightedGraph< T > &g, int s) {
  const auto INF1 = numeric_limits< T >::max();
  vector< T > dist(g.size(), INF1);

  using Pi = pair< T, int >;
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  dist[s] = 0;
  que.emplace(dist[s], s);
  while(!que.empty()) {
    T cost;
    int idx;
    tie(cost, idx) = que.top();
    que.pop();
    if(dist[idx] < cost) continue;
    for(auto &e : g[idx]) {
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      que.emplace(dist[e.to], e.to);
    }
  }
  return dist;
}


void solve(void)
{
  int N,M;
  cin>>N>>M;
  int S,G;
  cin>>S>>G;
  S--;G--;
  vector<pair<double,double> > vp;
  for (int i = 0; i < N; i++)
  {
    double X,Y;cin>>X>>Y;
    vp.push_back(make_pair(X,Y));
  }
  WeightedGraph<double> WG (N);
  for (int i = 0; i < M; i++)
  {
    int P,Q;
    cin>>P>>Q;
    P--;Q--;
    double D = sqrt(pow(vp[P].first - vp[Q].first ,2 ) + pow(vp[P].second - vp[Q].second ,2 ));
    WG[P].emplace_back(P,Q,D);
    WG[Q].emplace_back(Q,P,D);
  }
  auto path = dijkstra(WG,S);
  cout<<path[G]<<endl;
  

  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}
0