結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー ngtkanangtkana
提出日時 2020-04-20 19:40:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,101 bytes
コンパイル時間 2,630 ms
コンパイル使用メモリ 216,284 KB
実行使用メモリ 37,064 KB
最終ジャッジ日時 2024-04-09 22:42:16
合計ジャッジ時間 13,520 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 RE -
testcase_02 AC 188 ms
20,688 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 52 ms
12,240 KB
testcase_08 AC 198 ms
35,900 KB
testcase_09 AC 18 ms
6,940 KB
testcase_10 AC 87 ms
18,128 KB
testcase_11 AC 59 ms
13,352 KB
testcase_12 RE -
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 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 AC 409 ms
37,064 KB
testcase_42 AC 96 ms
13,976 KB
testcase_43 AC 196 ms
21,288 KB
testcase_44 AC 56 ms
10,172 KB
testcase_45 AC 190 ms
21,048 KB
testcase_46 AC 2 ms
6,944 KB
testcase_47 AC 1 ms
6,944 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<n-1;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);
    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<<dist.at(t)<<'\n';
}
0