結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー cardano1016cardano1016
提出日時 2020-05-29 21:46:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 242 ms / 2,000 ms
コード長 3,196 bytes
コンパイル時間 1,168 ms
コンパイル使用メモリ 117,812 KB
実行使用メモリ 31,672 KB
最終ジャッジ日時 2024-04-23 21:10:13
合計ジャッジ時間 6,750 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 104 ms
17,664 KB
testcase_03 AC 145 ms
28,200 KB
testcase_04 AC 134 ms
27,540 KB
testcase_05 AC 105 ms
26,628 KB
testcase_06 AC 108 ms
26,748 KB
testcase_07 AC 39 ms
10,752 KB
testcase_08 AC 140 ms
31,092 KB
testcase_09 AC 13 ms
6,940 KB
testcase_10 AC 61 ms
15,744 KB
testcase_11 AC 43 ms
12,032 KB
testcase_12 AC 18 ms
7,168 KB
testcase_13 AC 99 ms
17,700 KB
testcase_14 AC 120 ms
20,668 KB
testcase_15 AC 144 ms
23,476 KB
testcase_16 AC 60 ms
12,804 KB
testcase_17 AC 162 ms
24,832 KB
testcase_18 AC 42 ms
9,992 KB
testcase_19 AC 149 ms
24,096 KB
testcase_20 AC 36 ms
9,472 KB
testcase_21 AC 47 ms
11,392 KB
testcase_22 AC 135 ms
21,936 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 17 ms
6,944 KB
testcase_26 AC 75 ms
15,088 KB
testcase_27 AC 75 ms
14,512 KB
testcase_28 AC 140 ms
21,524 KB
testcase_29 AC 13 ms
6,940 KB
testcase_30 AC 158 ms
24,340 KB
testcase_31 AC 98 ms
19,796 KB
testcase_32 AC 63 ms
13,632 KB
testcase_33 AC 154 ms
25,264 KB
testcase_34 AC 46 ms
10,624 KB
testcase_35 AC 150 ms
24,680 KB
testcase_36 AC 2 ms
6,944 KB
testcase_37 AC 3 ms
6,944 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 3 ms
6,940 KB
testcase_40 AC 2 ms
6,944 KB
testcase_41 AC 242 ms
31,672 KB
testcase_42 AC 61 ms
12,160 KB
testcase_43 AC 108 ms
18,560 KB
testcase_44 AC 35 ms
8,960 KB
testcase_45 AC 108 ms
18,048 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
class Dijkstra{
    private:
        struct edge{
            int to;
            double cost;
        };
        vector<vector<edge>> G;
        vector<double> d;
        int siz;
    public:
        Dijkstra(int n){
            G.resize(n);
            siz = n;
        }
        void add_edge(int from,int to,double cost){
            G[from].push_back(edge{to,cost});
        }
        vector<double> dijkstra(int s){
            priority_queue<P,vector<P>,greater<P>> q;
            d.assign(siz,1e9);
            d[s] = 0.0;
            q.push(P(0,s));
            while(!q.empty()){
                P p = q.top();q.pop();
                int v = p.second;
                if (d[v] < p.first) continue;
                for(edge &e:G[v]){
                    if (chmin(d[e.to],d[v]+e.cost)){
                        q.push(P(d[e.to],e.to));
                    }
                }
            }
            return d;
        }
};
double dis(double x1,double y1,double x2,double y2){
    return sqrt(pow(x1-x2,2)+pow(y1-y2,2));
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,x,y;
    cin >> n >> m >> x >> y;
    x--;
    y--;
    vector<vector<double>> cost(n,vector<double>(2));
    rep(i,n){
        cin >> cost[i][0] >> cost[i][1];
    }
    Dijkstra g(n);
    ll p,q;
    rep(i,m){
        cin >> p >> q;
        p--;
        q--;
        g.add_edge(p,q,dis(cost[p][0],cost[p][1],cost[q][0],cost[q][1]));
        g.add_edge(q,p,dis(cost[p][0],cost[p][1],cost[q][0],cost[q][1]));
    }
    vector<double> d = g.dijkstra(x);
    printf("%.10f\n",d[y]);
}
0