結果

問題 No.848 なかよし旅行
ユーザー koi_kotyakoi_kotya
提出日時 2019-07-06 04:40:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,885 bytes
コンパイル時間 1,907 ms
コンパイル使用メモリ 172,624 KB
実行使用メモリ 7,096 KB
最終ジャッジ日時 2024-04-16 08:20:48
合計ジャッジ時間 4,021 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
7,096 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2 ms
6,940 KB
testcase_05 WA -
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 WA -
testcase_09 AC 4 ms
6,940 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 60 ms
6,940 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 7 ms
6,940 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 2 ms
6,940 KB
testcase_25 WA -
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 2 ms
6,944 KB
testcase_29 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int MAX_N = 2010;
ll INF = 1LL<<60;
vector<vector<P>> G(MAX_N);

void dijkstra(int s,vector<ll>& dist) {
    priority_queue<P,vector<P>,greater<P>> que;
    dist[s] = 0;
    que.push(P(0,s));
 
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v =  p.second;
        if (dist[v] < p.first) continue;
        for (int i = 0;i < G[v].size();++i) {
            P e = G[v][i];
            if (dist[e.first] > dist[v]+e.second) {
                dist[e.first] = dist[v]+e.second;
                que.push(P(dist[e.first],e.first));
            }
        }
    }
}

int main() {
    int n,m,p,q,t;
    cin >> n >> m >> p >> q >> t;
    for (int i = 0;i < m;++i) {
        int u,v,w;
        cin >> u >> v >> w;
        u--;v--;
        G[u].push_back(P(v,w));
        G[v].push_back(P(u,w));
    }
    p--;q--;
    vector<ll> dist1(n,INF),dist2(n,INF),dist3(n,INF);
    dijkstra(0,dist1);
    dijkstra(p,dist2);
    dijkstra(q,dist3);
    if (dist1[p]*2 > t || dist1[q]*2 > t) {
        cout << -1 << endl;
        return 0;
    }
    if (dist1[p]+dist2[q]+dist3[0] <= t) {
        cout << t << endl;
        return 0;
    }
    ll ans = 0;
    for (int i = 0;i < n;++i) {
        for (int j = 0;j < n;++j) {
            ll d = max(dist2[i],dist3[i])+max(dist2[j],dist3[j]);
            if (d+dist1[i]+dist1[j] > t) continue;
            ans = max(ans,t-d);
        }
    }
    cout << ans << endl;
    return 0;
}
0