結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー hs0319boyhs0319boy
提出日時 2020-05-29 21:52:02
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 412 ms / 2,000 ms
コード長 1,747 bytes
コンパイル時間 2,003 ms
コンパイル使用メモリ 181,828 KB
実行使用メモリ 24,636 KB
最終ジャッジ日時 2024-11-06 03:59:20
合計ジャッジ時間 10,583 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const double inf=1e9+7;
const ll INF=1e18;

vector<vector<pair<int,double>>> edge(200050);
vector<double> d(200050,inf);

void dijkstra(int s){
    priority_queue<pair<double,int>,vector<pair<double,int>>,greater<pair<double,int>>> q;
    d[s]=0;
    q.push(mp(0,s));
    while(q.size()){
        auto p=q.top();q.pop();
        auto v=p.second;
        if(d[v]<p.first)continue;
        for(auto e:edge[v]){
            if(d[e.first]>d[v]+e.second){
                d[e.first]=d[v]+e.second;
                q.push(mp(d[e.first],e.first));
            }
        }
    }
}

int main(){
    decp(7);
    int n,m,x,y;cin>>n>>m>>x>>y;
    vector<pair<double,double>> coor(n);
    double p,q;
    rep(i,n){
        cin>>p>>q;
        coor[i]=mp(p,q);
    }
    int P,Q;double tmp;
    rep(i,m){
        cin>>P>>Q;
        tmp=sqrt((coor[P-1].first-coor[Q-1].first)*(coor[P-1].first-coor[Q-1].first)+(coor[P-1].second-coor[Q-1].second)*(coor[P-1].second-coor[Q-1].second));
        edge[P].push_back(mp(Q,tmp));
        edge[Q].push_back(mp(P,tmp));
    }
    dijkstra(x);
    cout<<d[y]<<endl;
}
0