結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー udonmanudonman
提出日時 2020-09-17 09:07:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,324 bytes
コンパイル時間 2,528 ms
コンパイル使用メモリ 132,272 KB
実行使用メモリ 34,432 KB
最終ジャッジ日時 2023-09-04 07:05:20
合計ジャッジ時間 21,115 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 47 ms
10,080 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 WA -
testcase_22 RE -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 WA -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 WA -
testcase_37 RE -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 AC 1 ms
4,380 KB
testcase_47 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <numeric>
#include <cmath>
#include <iomanip> //cout << fixed << setprecision(15) << << endl;
#include <cassert>
#include <limits>
//#include "atcoder/all"

using namespace std;
//using namespace atcoder;

#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
//#define P pair<int,int>

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};

template<typename T>
class Graph
{
public:
    struct Edge
    {
        int to;
        T cost;
    };
    struct edge
    {
        int from;
        int to;
    };
    vector<vector<Edge>> g;
    int n;
    Graph(int n)
    {
        g.resize(n);
    }

    void Add(int from, int to, T cost)
    {
        g[from].push_back({to,cost});
        g[to].push_back({from,cost});
    }

};

template<typename T>
vector<T> dijkstra(Graph<T> G, int start)
{
    using P = pair<T,int>;
    vector<T> dist(G.n, numeric_limits<T>::max());
    priority_queue<P,vector<P>,greater<P>> pq;
    dist[start] = 0;
    pq.push({dist[start],start});
    while(!pq.empty())
    {
        T COST = pq.top().first;
        int v = pq.top().second;
        pq.pop();

        if(dist[v] < COST)
        {
            continue;
        }
        for(auto e : G.g[v])
        {
            int j = e.to;
            T c = e.cost;
            if(dist[j] > dist[v] + c)
            {
                dist[j] = dist[v] + c;
                pq.push({dist[j],j});
            }
        }
    }
    return dist;
}


int main(){
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    --x; --y;
    vector<double> p(n),q(n);
    rep(i,n) cin >> p[i] >> q[i];

    Graph<double> G(n);
    rep(i,m){
        int P, Q; cin >> P >> Q;
        P--; Q--;
        double Co = sqrt(pow((p[P]-p[Q]),2) + pow((q[P]-q[Q]),2));
        G.Add(P,Q,Co);
    }
    vector<double> ans;
    ans = dijkstra(G,x);
    cout << fixed << setprecision(7) << ans[y] << endl;
}

0