結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー ngtkana
提出日時 2020-04-20 19:44:01
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
MLE  
実行時間 -
コード長 2,103 bytes
コンパイル時間 3,618 ms
コンパイル使用メモリ 214,520 KB
最終ジャッジ日時 2025-01-09 21:59:43
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample MLE * 2
other AC * 21 TLE * 15 MLE * 10
権限があれば一括ダウンロードができます

ソースコード

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);
    for(lint k=0;k<(lint)que.size();k++){
        lint x=que.at(k);
        ckd.at(x)=true;
        for(auto[y,_]:g.at(x)){
            if(ckd.at(y))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