結果

問題 No.848 なかよし旅行
ユーザー koyoprokoyopro
提出日時 2020-03-30 00:39:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 2,221 bytes
コンパイル時間 2,284 ms
コンパイル使用メモリ 153,860 KB
実行使用メモリ 24,364 KB
最終ジャッジ日時 2023-08-07 20:00:38
合計ジャッジ時間 4,082 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
24,364 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 24 ms
7,372 KB
testcase_12 AC 30 ms
8,576 KB
testcase_13 AC 39 ms
10,460 KB
testcase_14 AC 17 ms
5,104 KB
testcase_15 AC 36 ms
10,188 KB
testcase_16 AC 59 ms
15,028 KB
testcase_17 AC 41 ms
11,436 KB
testcase_18 AC 23 ms
7,112 KB
testcase_19 AC 21 ms
6,576 KB
testcase_20 AC 13 ms
4,376 KB
testcase_21 AC 48 ms
12,584 KB
testcase_22 AC 45 ms
13,812 KB
testcase_23 AC 23 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 63 ms
15,272 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)

int dxy[] = {0, 1, 0, -1, 0};

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 5
#else
#define SIZE 2222
#endif

int N,M,P,Q,T;
typedef pair<int, int> Edge;
typedef pair<int, int> I;
vector< vector<Edge> > E;

int DP[3][SIZE];
void dijkstra(int a, int s) {
    auto dp = DP[a];
    REP(i,SIZE) dp[i]=LONG_LONG_MAX;
    priority_queue<I, vector<I>, greater<I>> que;
    dp[s]=0;
    que.push(*new I(0,s));
    while(que.size()) {
        I i = que.top();
        que.pop();
        if (i.first > dp[i.second]) continue;
        for (auto e:E[i.second]) {
            int c = i.first + e.second;
            if (dp[e.first] > c) {
                dp[e.first] = c;
                que.push(*new I(c, e.first));
            }
        }
    }
}

void solve() {
    cin>>N>>M>>P>>Q>>T;
    P--, Q--;
    int a,b,c;
    E.resize(N);
    REP(i,M) {
        cin>>a>>b>>c;
        a--,b--;
        E[a].push_back(*new Edge(b,c));
        E[b].push_back(*new Edge(a,c));
    }
    dijkstra(0, 0);
    dijkstra(1, P);
    dijkstra(2, Q);
    
    if ((DP[0][P] + DP[1][Q] + DP[2][0]) <= T) {
        cout << T << endl;
        return;
    }
    int ans = -1;
    REP(i,N)REP(j,N) {
        int t0 = DP[0][i] + DP[1][i] + DP[1][j] + DP[0][j];
        int t1 = DP[0][i] + DP[2][i] + DP[2][j] + DP[0][j];
        int t = max(t0, t1);
        if (t > T) continue;
        int d = max(DP[1][i] + DP[1][j], DP[2][i] + DP[2][j]);
        ans = max(ans, T-d);
    }
    cout << ans << endl;
}
0