結果

問題 No.2805 Go to School
ユーザー otoshigootoshigo
提出日時 2024-07-12 22:00:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 281 ms / 2,000 ms
コード長 1,676 bytes
コンパイル時間 2,712 ms
コンパイル使用メモリ 215,788 KB
実行使用メモリ 23,120 KB
最終ジャッジ日時 2024-07-16 01:39:27
合計ジャッジ時間 7,136 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 82 ms
16,768 KB
testcase_05 AC 111 ms
14,140 KB
testcase_06 AC 64 ms
9,260 KB
testcase_07 AC 52 ms
9,124 KB
testcase_08 AC 87 ms
14,324 KB
testcase_09 AC 63 ms
9,320 KB
testcase_10 AC 53 ms
9,052 KB
testcase_11 AC 281 ms
20,956 KB
testcase_12 AC 149 ms
14,440 KB
testcase_13 AC 228 ms
18,608 KB
testcase_14 AC 26 ms
6,944 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 90 ms
11,308 KB
testcase_19 AC 60 ms
8,744 KB
testcase_20 AC 144 ms
15,744 KB
testcase_21 AC 235 ms
20,012 KB
testcase_22 AC 92 ms
10,708 KB
testcase_23 AC 148 ms
14,476 KB
testcase_24 AC 140 ms
14,468 KB
testcase_25 AC 41 ms
8,540 KB
testcase_26 AC 166 ms
23,120 KB
testcase_27 AC 88 ms
16,304 KB
testcase_28 AC 9 ms
6,940 KB
testcase_29 AC 14 ms
7,680 KB
testcase_30 AC 46 ms
12,208 KB
testcase_31 AC 73 ms
9,856 KB
testcase_32 AC 114 ms
18,604 KB
testcase_33 AC 178 ms
18,612 KB
testcase_34 AC 3 ms
6,944 KB
testcase_35 AC 3 ms
6,944 KB
testcase_36 AC 78 ms
9,088 KB
testcase_37 AC 77 ms
10,112 KB
testcase_38 AC 177 ms
15,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

const ll INF=1LL<<60;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,M,L;
    ll S,E;
    cin>>N>>M>>L>>S>>E;
    vector<vector<pair<int,ll>>>G(N);
    for(int i=0;i<M;i++){
        int a,b;
        ll t;
        cin>>a>>b>>t;
        a--;
        b--;
        G[a].push_back(make_pair(b,t));
        G[b].push_back(make_pair(a,t));
    }
    vector<int>T(L);
    for(int i=0;i<L;i++){
        cin>>T[i];
        T[i]--;
    }
    auto f=[&](int s)-> vector<ll> {
        priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>>pq;
        pq.push(make_pair(0,s));
        vector<ll>dist(N,INF);
        dist[s]=0;
        while(pq.size()){
            auto[c,x]=pq.top();
            pq.pop();
            if(dist[x]<c)continue;
            for(auto[i,e]:G[x]){
                if(chmin(dist[i],c+e)){
                    pq.push(make_pair(dist[i],i));
                }
            }
        }
        return dist;
    };
    vector<ll>ds=f(0),dt=f(N-1);
    if(ds[N-1]==INF){
        cout<<-1<<"\n";
    }else{
        ll ans=INF;
        for(int i=0;i<L;i++){
            int t=T[i];
            if(ds[t]==INF||dt[t]==INF)continue;
            if(ds[t]<=S+E-1){
                chmin(ans,max(S,ds[t])+1+dt[t]);
            }
        }
        if(ans==INF)cout<<-1<<"\n";
        else cout<<ans<<"\n";
    }
}
0