結果

問題 No.848 なかよし旅行
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2019-07-06 10:16:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,587 bytes
コンパイル時間 2,069 ms
コンパイル使用メモリ 177,024 KB
実行使用メモリ 8,676 KB
最終ジャッジ日時 2024-04-16 08:28:11
合計ジャッジ時間 3,682 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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(i, 0, N) {
		ll tot = s[i] * 2 + max(p[i], q[i]) * 2;
		if (tot <= T) {
			chmax(ans, T - max(p[i], q[i]) * 2);
		}
	}
	cout << ans << endl;
}




0