結果

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

template <typename T>
void dijkstra(int s,vector<vector<pair<int,T>>>& edges,vector<T>& dist) {
    priority_queue<pair<T,int>,vector<pair<T,int>>,greater<pair<T,int>>> que;
    dist[s] = 0;
    que.push(make_pair(0,s));
    while (!que.empty()) {
        pair<ll,int> p = que.top();
        que.pop();
        int v =  p.second;
        if (dist[v] < p.first) continue;
        for (pair<int,T>& e : edges[v]) {
            if (dist[e.first] > dist[v]+e.second) {
                dist[e.first] = dist[v]+e.second;
                que.push(make_pair(dist[e.first],e.first));
            }
        }
    }
}

int main() {
    int n,m,x,y;
    cin >> n >> m >> x >> y;
    x--;y--;
    vector<int> p(n),q(n);
    vector<vector<pair<int,double>>> edges(n);
    for (int i = 0;i < n;++i) cin >> p[i] >> q[i];
    for (int i = 0;i < m;++i) {
        int u,v;
        scanf("%d%d",&u,&v);
        u--;v--;
        double d = sqrt((p[u]-p[v])*(p[u]-p[v])+(q[u]-q[v])*(q[u]-q[v]));
        edges[u].push_back({v,d});
        edges[v].push_back({u,d});
    }
    vector<double> dist(n,1e9);
    dijkstra<double>(x,edges,dist);
    cout << fixed << setprecision(12) << dist[y] << endl;
}
0