結果

問題 No.848 なかよし旅行
ユーザー kappybarkappybar
提出日時 2020-04-09 14:20:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 222 ms / 2,000 ms
コード長 1,850 bytes
コンパイル時間 1,870 ms
コンパイル使用メモリ 177,460 KB
実行使用メモリ 14,888 KB
最終ジャッジ日時 2024-04-25 14:15:30
合計ジャッジ時間 4,918 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 220 ms
14,208 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 5 ms
6,940 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 62 ms
6,944 KB
testcase_12 AC 89 ms
8,552 KB
testcase_13 AC 124 ms
9,804 KB
testcase_14 AC 28 ms
6,940 KB
testcase_15 AC 116 ms
9,740 KB
testcase_16 AC 219 ms
14,888 KB
testcase_17 AC 139 ms
10,796 KB
testcase_18 AC 60 ms
6,944 KB
testcase_19 AC 49 ms
6,944 KB
testcase_20 AC 12 ms
6,940 KB
testcase_21 AC 181 ms
14,540 KB
testcase_22 AC 208 ms
14,512 KB
testcase_23 AC 25 ms
6,940 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 222 ms
11,784 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 2 ms
6,944 KB
testcase_29 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll =  long long ;
using P = pair<int,int> ;
using Pll = pair<ll,ll>;
const ll INF = 1e18;
const int MOD = 1000000007;

ll v = 2005,e;
vector<vector<pair<ll,ll>>> graph(v,vector<pair<ll,ll>>());

vector<ll> dijkstra(ll start){
    vector<ll> shortest(v);
    vector<bool> visited(v,false);
    priority_queue<pair<ll,ll>,vector<pair<ll ,ll>>,greater<pair<ll,ll>>> pq;
    pq.push(make_pair(0,start));
    while (!pq.empty()){
        pair<ll,ll> now = pq.top();
        pq.pop();
        ll cost,node;
        tie(cost,node) = now;
        if(visited[node]){
            continue;
        }else{
            shortest[node] = cost;
            visited[node] = true;
            for(pair<ll,ll> next:graph[node]){
                ll next_cost,next_node;
                tie(next_cost,next_node) = next;
                pq.push(make_pair(cost+next_cost,next_node));
            }
        }
    }
    return shortest;
}

int main(){
    int p,q;
    ll time;
    cin >> v >> e >> p >> q >> time;
    --p;--q;
    rep(i,e){
        int a,b;
        ll c;
        cin >> a >> b >> c;
        --a;--b;
        graph[a].push_back(Pll(c,b));
        graph[b].push_back(Pll(c,a));
    }
    vector<ll> dis_zero = dijkstra(0);
    vector<ll> dis_p = dijkstra(p);
    vector<ll> dis_q = dijkstra(q);
    if(dis_zero[p] + dis_p[q] + dis_zero[q] <= time){
        cout << time << endl;
        return 0;
    }
    ll ans = -1;
    rep(i,v)rep(j,v){
        ll s1 = dis_zero[i];
        ll t1 = dis_p[i];
        ll u1 = dis_q[i];
        ll s2 = dis_zero[j];
        ll t2 = dis_p[j];
        ll u2 = dis_q[j];
        if(s1+t1+s2+t2 <= time && s1+u1+s2+u2 <= time){
            ans = max(ans,time - max(t1+t2,u1+u2));
        }
    }
    cout << ans << endl;
    return 0;
}
0