結果

問題 No.848 なかよし旅行
ユーザー satashunsatashun
提出日時 2019-07-05 22:13:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 156 ms / 2,000 ms
コード長 1,819 bytes
コンパイル時間 1,697 ms
コンパイル使用メモリ 177,372 KB
実行使用メモリ 40,264 KB
最終ジャッジ日時 2023-08-07 19:40:54
合計ジャッジ時間 4,300 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 156 ms
40,264 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
8,604 KB
testcase_09 AC 4 ms
8,388 KB
testcase_10 AC 4 ms
8,332 KB
testcase_11 AC 45 ms
30,964 KB
testcase_12 AC 56 ms
33,212 KB
testcase_13 AC 72 ms
35,708 KB
testcase_14 AC 28 ms
34,732 KB
testcase_15 AC 67 ms
33,812 KB
testcase_16 AC 108 ms
37,208 KB
testcase_17 AC 72 ms
31,952 KB
testcase_18 AC 42 ms
28,900 KB
testcase_19 AC 40 ms
30,756 KB
testcase_20 AC 27 ms
34,928 KB
testcase_21 AC 88 ms
32,076 KB
testcase_22 AC 82 ms
12,784 KB
testcase_23 AC 34 ms
35,148 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 110 ms
37,196 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}
 
template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const int maxn = 2010;
const ll INF = 1e18;

vector<pii> g[maxn];
ll d[maxn][maxn];

int main() {
	int N, M, P, Q, T; cin >> N >> M >> P >> Q >> T;
	--P; --Q;

	rep(i, M) {
		int a, b, c; cin >> a >> b >> c;
		--a; --b;
		g[a].eb(b, c);
		g[b].eb(a, c);
	}

	rep(i, N) {
		rep(j, N) d[i][j] = INF;
		d[i][i] = 0;
	}

	vector<int> cand;
	cand.pb(0); cand.pb(P); cand.pb(Q);

	for (int i : cand) {
		using Data = pair<ll, int>;
		priority_queue<Data, vector<Data>, greater<Data>> que;
		que.push(mp(0ll, i));

		while (!que.empty()) {
			auto t = que.top(); que.pop();
			int v = t.se;
			if (t.fi > d[i][v]) continue;
			for (pii e : g[v]) {
				if (d[i][e.fi] > d[i][v] + e.se) {
					d[i][e.fi] = d[i][v] + e.se;
					que.push(mp(d[i][e.fi], e.fi));
				}
			}
		}
	}

	int ans = -1;
	if (d[0][P] + d[P][Q] + d[0][Q] <= T) ans = T;

	rep(i, N) {
		rep(j, N) {
			ll t = d[0][i] + d[0][j] + max(d[P][i] + d[P][j], d[Q][i] + d[Q][j]);
			if (t <= T) {
				ans = max<int>(ans, T - max(d[P][i] + d[P][j], d[Q][i] + d[Q][j]));
			}
		}
	}

	cout << ans << endl;

	return 0;
}
0