結果
問題 | No.848 なかよし旅行 |
ユーザー | 👑 はまやんはまやん |
提出日時 | 2019-07-06 10:23:38 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 89 ms / 2,000 ms |
コード長 | 2,613 bytes |
コンパイル時間 | 1,610 ms |
コンパイル使用メモリ | 177,716 KB |
実行使用メモリ | 8,804 KB |
最終ジャッジ日時 | 2023-08-07 19:47:02 |
合計ジャッジ時間 | 3,432 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 89 ms
8,804 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 1 ms
4,376 KB |
testcase_05 | AC | 2 ms
4,380 KB |
testcase_06 | AC | 2 ms
4,376 KB |
testcase_07 | AC | 1 ms
4,376 KB |
testcase_08 | AC | 2 ms
4,380 KB |
testcase_09 | AC | 2 ms
4,376 KB |
testcase_10 | AC | 2 ms
4,380 KB |
testcase_11 | AC | 15 ms
4,680 KB |
testcase_12 | AC | 20 ms
4,684 KB |
testcase_13 | AC | 26 ms
5,096 KB |
testcase_14 | AC | 11 ms
4,376 KB |
testcase_15 | AC | 24 ms
5,208 KB |
testcase_16 | AC | 39 ms
5,700 KB |
testcase_17 | AC | 27 ms
5,336 KB |
testcase_18 | AC | 15 ms
4,376 KB |
testcase_19 | AC | 14 ms
4,380 KB |
testcase_20 | AC | 8 ms
4,380 KB |
testcase_21 | AC | 32 ms
5,452 KB |
testcase_22 | AC | 30 ms
5,288 KB |
testcase_23 | AC | 20 ms
4,508 KB |
testcase_24 | AC | 1 ms
4,380 KB |
testcase_25 | AC | 44 ms
5,916 KB |
testcase_26 | AC | 2 ms
4,376 KB |
testcase_27 | AC | 2 ms
4,376 KB |
testcase_28 | AC | 2 ms
4,376 KB |
testcase_29 | AC | 1 ms
4,380 KB |
ソースコード
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } //--------------------------------------------------------------------------------------------------- template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>; int vis[101010]; void dijk(int s, vector<vector<pair<int,int>>> &E, vector<ll> &D) { int N = E.size(); rep(i, 0, N) D[i] = infl; rep(i, 0, N) vis[i] = 0; min_priority_queue<pair<ll, int>> que; D[s] = 0; que.push({ 0, s }); while (!que.empty()) { auto q = que.top(); que.pop(); ll cst = q.first; int cu = q.second; if (vis[cu]) continue; vis[cu] = 1; fore(p, E[cu]) { ll cst2 = cst + p.second; int to = p.first; if (chmin(D[to], cst2)) que.push({ D[to], to }); } } } /*--------------------------------------------------------------------------------------------------- ∧_∧ ∧_∧ (´<_` ) Welcome to My Coding Space! ( ´_ゝ`) / ⌒i @hamayanhamayan / \ | | / / ̄ ̄ ̄ ̄/ | __(__ニつ/ _/ .| .|____ \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int N, M, P, Q, T; //--------------------------------------------------------------------------------------------------- void _main() { cin >> N >> M >> P >> Q >> T; P--; Q--; vector<vector<pair<int, int>>> E(N); rep(i, 0, M) { int a, b, c; cin >> a >> b >> c; a--; b--; E[a].push_back({ b, c }); E[b].push_back({ a, c }); } vector<ll> s(N), p(N), q(N); dijk(0, E, s); dijk(P, E, p); dijk(Q, E, q); if (s[P] + p[Q] + q[0] <= T) { cout << T << endl; return; } ll ans = -1; rep(a, 0, N) rep(b, 0, N) { ll tot = s[a] + max(p[a] + p[b], q[a] + q[b]) + s[b]; if (tot <= T) { chmax(ans, T - (tot - s[a] - s[b])); } } cout << ans << endl; }