結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー Jiro_tech15Jiro_tech15
提出日時 2020-05-29 21:36:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 310 ms / 2,000 ms
コード長 1,641 bytes
コンパイル時間 968 ms
コンパイル使用メモリ 105,272 KB
実行使用メモリ 22,640 KB
最終ジャッジ日時 2024-04-23 20:33:04
合計ジャッジ時間 7,610 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,448 KB
testcase_01 AC 4 ms
8,448 KB
testcase_02 AC 132 ms
15,656 KB
testcase_03 AC 204 ms
22,640 KB
testcase_04 AC 204 ms
22,508 KB
testcase_05 AC 172 ms
22,544 KB
testcase_06 AC 170 ms
22,640 KB
testcase_07 AC 60 ms
11,688 KB
testcase_08 AC 223 ms
21,928 KB
testcase_09 AC 23 ms
9,404 KB
testcase_10 AC 99 ms
14,376 KB
testcase_11 AC 68 ms
12,328 KB
testcase_12 AC 45 ms
11,904 KB
testcase_13 AC 135 ms
17,832 KB
testcase_14 AC 153 ms
20,520 KB
testcase_15 AC 180 ms
20,532 KB
testcase_16 AC 93 ms
15,396 KB
testcase_17 AC 201 ms
21,808 KB
testcase_18 AC 69 ms
13,184 KB
testcase_19 AC 190 ms
20,728 KB
testcase_20 AC 55 ms
11,576 KB
testcase_21 AC 83 ms
14,772 KB
testcase_22 AC 185 ms
21,160 KB
testcase_23 AC 7 ms
8,576 KB
testcase_24 AC 6 ms
8,832 KB
testcase_25 AC 44 ms
11,520 KB
testcase_26 AC 106 ms
15,488 KB
testcase_27 AC 105 ms
15,848 KB
testcase_28 AC 183 ms
20,964 KB
testcase_29 AC 28 ms
10,624 KB
testcase_30 AC 198 ms
21,240 KB
testcase_31 AC 130 ms
18,316 KB
testcase_32 AC 86 ms
14,376 KB
testcase_33 AC 185 ms
22,036 KB
testcase_34 AC 71 ms
13,180 KB
testcase_35 AC 184 ms
21,744 KB
testcase_36 AC 6 ms
8,576 KB
testcase_37 AC 6 ms
8,704 KB
testcase_38 AC 5 ms
8,576 KB
testcase_39 AC 6 ms
8,576 KB
testcase_40 AC 5 ms
8,448 KB
testcase_41 AC 310 ms
22,472 KB
testcase_42 AC 82 ms
12,460 KB
testcase_43 AC 143 ms
15,912 KB
testcase_44 AC 52 ms
11,048 KB
testcase_45 AC 137 ms
15,784 KB
testcase_46 AC 5 ms
8,448 KB
testcase_47 AC 5 ms
8,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define MAX_V 200005
//lower_bound使え

struct edge{int to; double cost;};
typedef pair<double, int> P;//最短距離、頂点番号

int V;
vector<edge> G[MAX_V];
double d[MAX_V];

void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P> > que;
  fill(d,d+V,LINF);
  d[s] = 0;
  que.push(P(0,s));

  while(!que.empty()){
    P p = que.top(); que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    rep(i, G[v].size()){
      edge e = G[v][i];
      if(d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

/*
 * 頂点数をVに代入すること
 */
int main(void){
  cout<<fixed<<setprecision(15);
  int n,m;cin>>n>>m;
  V=n;
  int s,t;cin>>s>>t;s--;t--;

  vector<ll> X,Y;
  rep(i,n){
    int p,q;cin>>p>>q;
    X.push_back(p);
    Y.push_back(q);
  }
  rep(i,m){
    int p,q;cin>>p>>q;
    p--;q--;
    double dist = sqrt((X[p]-X[q]) * (X[p]-X[q]) + (Y[p]-Y[q]) * (Y[p]-Y[q]));
    G[p].push_back({q,dist});
    G[q].push_back({p,dist});
  }

  dijkstra(s);
  cout << d[t] << endl;
  return 0;
}
0