結果

問題 No.848 なかよし旅行
ユーザー 👑 jupirojupiro
提出日時 2020-02-14 20:16:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,576 bytes
コンパイル時間 1,561 ms
コンパイル使用メモリ 130,416 KB
実行使用メモリ 16,164 KB
最終ジャッジ日時 2024-04-16 01:10:08
合計ジャッジ時間 7,194 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
16,164 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
5,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 4 ms
5,376 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

void dijkstra(ll start, vector<vector<pair<ll, ll>>>& graph, vector<ll>& dist) {
	dist[start] = 0;
	priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
	vector<bool> used(dist.size(), false);
	pq.push(make_pair(0, start));
	while (!pq.empty()) {
		ll d, node;
		tie(d, node) = pq.top();
		pq.pop();
		if (used[node]) continue;
		used[node] = true;
		for (pair<ll, ll> element : graph[node]) {
			ll new_d, new_node;
			tie(new_node, new_d) = element;
			new_d += d;
			if (new_d < dist[new_node]) {
				dist[new_node] = new_d;
				pq.push(make_pair(dist[new_node], new_node));
			}
		}
	}
}
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	ll N, M, P, Q, T; scanf("%lld %lld %lld %lld %lld", &N, &M, &P, &Q, &T);
	P--; Q--;
	vector<vector<pair<ll, ll>>> g(N);
	for (ll i = 0; i < M; i++) {
		ll a, b, c; scanf("%lld %lld %lld", &a, &b, &c);
		a--; b--;
		g[a].emplace_back(b, c);
		g[b].emplace_back(a, c);
	}
	vector<vector<ll>> dist(3, vector<ll>(N, INF));
	dijkstra(0, g, dist[0]);
	dijkstra(P, g, dist[1]);
	dijkstra(Q, g, dist[2]);
	if (max(dist[0][P] , dist[0][Q]) * 2 > T) {
		//cout << dist[0][P] << " " << dist[0][Q] << endl;
		puts("-1");
		return 0;
	}
	if (dist[0][P] + dist[1][Q] + dist[0][Q] <= T) {
		cout << T << endl;
		return 0;
	}
	ll res = 0;
	for (ll i = 0; i < N; i++) {
		for (ll j = 0; j < N; j++) {
			ll len1 = dist[0][i];
			ll len2 = dist[1][i];
			ll len3 = dist[2][i];
			ll len4 = dist[1][j];
			ll len5 = dist[2][j];
			ll len6 = dist[0][j];
			if (len1 + len6 + max(len2 + len4, len3 + len5) <= T) {
				cout << i << " " << j << endl;
				chmax(res, T - max(len2 + len4, len3 + len5));
			}
		}
	}
	cout << res << endl;
	return 0;
}
0