結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー ngtkanangtkana
提出日時 2020-04-20 19:48:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 343 ms / 2,000 ms
コード長 2,141 bytes
コンパイル時間 2,588 ms
コンパイル使用メモリ 216,004 KB
実行使用メモリ 38,736 KB
最終ジャッジ日時 2024-04-09 22:42:27
合計ジャッジ時間 9,353 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 141 ms
20,812 KB
testcase_03 AC 200 ms
38,736 KB
testcase_04 AC 198 ms
36,872 KB
testcase_05 AC 157 ms
38,368 KB
testcase_06 AC 162 ms
38,028 KB
testcase_07 AC 48 ms
12,244 KB
testcase_08 AC 184 ms
35,992 KB
testcase_09 AC 16 ms
6,940 KB
testcase_10 AC 79 ms
18,004 KB
testcase_11 AC 54 ms
13,480 KB
testcase_12 AC 40 ms
11,008 KB
testcase_13 AC 157 ms
23,564 KB
testcase_14 AC 171 ms
31,124 KB
testcase_15 AC 211 ms
32,984 KB
testcase_16 AC 98 ms
18,268 KB
testcase_17 AC 233 ms
36,492 KB
testcase_18 AC 70 ms
14,328 KB
testcase_19 AC 215 ms
34,160 KB
testcase_20 AC 50 ms
10,996 KB
testcase_21 AC 87 ms
16,936 KB
testcase_22 AC 192 ms
30,680 KB
testcase_23 AC 4 ms
6,940 KB
testcase_24 AC 3 ms
6,940 KB
testcase_25 AC 37 ms
10,496 KB
testcase_26 AC 104 ms
20,204 KB
testcase_27 AC 103 ms
20,500 KB
testcase_28 AC 198 ms
33,072 KB
testcase_29 AC 22 ms
8,184 KB
testcase_30 AC 207 ms
35,256 KB
testcase_31 AC 139 ms
28,480 KB
testcase_32 AC 85 ms
18,224 KB
testcase_33 AC 211 ms
38,548 KB
testcase_34 AC 72 ms
14,712 KB
testcase_35 AC 217 ms
36,584 KB
testcase_36 AC 3 ms
6,940 KB
testcase_37 AC 4 ms
6,940 KB
testcase_38 AC 3 ms
6,940 KB
testcase_39 AC 4 ms
6,944 KB
testcase_40 AC 3 ms
6,944 KB
testcase_41 AC 343 ms
37,136 KB
testcase_42 AC 78 ms
13,980 KB
testcase_43 AC 145 ms
21,288 KB
testcase_44 AC 47 ms
10,168 KB
testcase_45 AC 142 ms
21,044 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* validator */

#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using ld=long double;
template<class T> using numr=std::numeric_limits<T>;

int main(){
    auto read=[]{
        std::string s;std::getline(std::cin,s);
        lint n=s.length();
        lint l=0,r;
        for(r=l;r<n&&s.at(r)!=' ';r++);
        assert(r-l<=9);
        lint x=std::stoll(s.substr(l,r-l));
        l=r+1;
        for(r=l;r<n&&s.at(r)!=' ';r++);
        assert(r-l<=9);
        lint y=std::stoll(s.substr(l,r-l));
        return std::pair{x,y};
    };
    auto[n,m]=read();
    assert(2<=n&&n<=200'000&&n-1<=m&&m<=std::min(n*(n-1)/2,200'000ll));
    auto[s,t]=read();
    assert(1<=s&&s<=n&&1<=t&&t<=n);
    s--,t--;
    std::vector<std::pair<ld,ld>>pt(n);
    for(lint i=0;i<n;i++){
        auto[x,y]=read();
        assert(-1'000<=x&&x<=1'000&&-1'000<=y&&y<=1'000);
        pt.at(i)={x,y};
    }
    std::vector<std::vector<std::pair<lint,ld>>>g(n);
    for(lint i=0;i<m;i++){
        auto[u,v]=read();
        assert(1<=u&&u<=n&&1<=v&&v<=n);
        u--,v--;
        ld w=std::hypot(pt.at(u).first-pt.at(v).first,pt.at(u).second-pt.at(v).second);
        g.at(u).emplace_back(v,w);
        g.at(v).emplace_back(u,w);
    }
    std::vector<lint>que,ckd(n);
    que.push_back(s);
    ckd.at(s)=true;
    for(lint k=0;k<(lint)que.size();k++){
        lint x=que.at(k);
        for(auto[y,_]:g.at(x)){
            if(std::exchange(ckd.at(y),true))continue;
            que.push_back(y);
        }
    }
    assert(ckd.at(t));
    assert(!std::cin.eof());
    std::string emplyline;std::getline(std::cin,emplyline);
    assert(std::cin.eof());

    ld inf=numr<ld>::infinity();
    std::vector<ld>dist(n,inf);
    std::priority_queue<std::pair<ld,lint>>pque;
    dist.at(s)=0;
    pque.emplace(0,s);
    while(!pque.empty()){
        lint x;std::tie(std::ignore,x)=pque.top();pque.pop();
        for(auto[y,w]:g.at(x)){
            ld d=dist.at(x)+w;
            if(dist.at(y)<=d)continue;
            dist.at(y)=d;
            pque.emplace(-d,y);
        }
    }
    std::cout<<std::setprecision(5)<<dist.at(t)<<'\n';
}
0