結果

問題 No.848 なかよし旅行
ユーザー koyoprokoyopro
提出日時 2020-03-30 00:39:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 2,221 bytes
コンパイル時間 1,455 ms
コンパイル使用メモリ 168,656 KB
実行使用メモリ 24,352 KB
最終ジャッジ日時 2024-04-25 14:14:28
合計ジャッジ時間 3,224 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
24,352 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 21 ms
7,296 KB
testcase_12 AC 27 ms
8,448 KB
testcase_13 AC 35 ms
10,240 KB
testcase_14 AC 13 ms
6,944 KB
testcase_15 AC 34 ms
9,984 KB
testcase_16 AC 55 ms
14,848 KB
testcase_17 AC 38 ms
11,392 KB
testcase_18 AC 19 ms
7,040 KB
testcase_19 AC 18 ms
6,940 KB
testcase_20 AC 9 ms
6,944 KB
testcase_21 AC 45 ms
12,544 KB
testcase_22 AC 45 ms
13,568 KB
testcase_23 AC 18 ms
6,944 KB
testcase_24 AC 1 ms
6,944 KB
testcase_25 AC 61 ms
14,976 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 1 ms
6,944 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,940 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