結果

問題 No.848 なかよし旅行
ユーザー tempura_pptempura_pp
提出日時 2019-03-16 01:03:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,513 bytes
コンパイル時間 1,034 ms
コンパイル使用メモリ 105,452 KB
実行使用メモリ 52,588 KB
最終ジャッジ日時 2024-04-16 06:54:43
合計ジャッジ時間 7,616 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:60:25: warning: '*dist[0][<unknown>]' may be used uninitialized [-Wmaybe-uninitialized]
   60 |         ll ret=dist[0][p]+dist[p][q]+dist[q][0];
      |                ~~~~~~~~~^
main.cpp:60:36: warning: '*dist[<unknown>][<unknown>]' may be used uninitialized [-Wmaybe-uninitialized]
   60 |         ll ret=dist[0][p]+dist[p][q]+dist[q][0];
      |                           ~~~~~~~~~^
main.cpp:60:47: warning: '*dist[<unknown>][0]' may be used uninitialized [-Wmaybe-uninitialized]
   60 |         ll ret=dist[0][p]+dist[p][q]+dist[q][0];
      |                                      ~~~~~~~~~^

ソースコード

diff #

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

using G=vector<vector<pair<ll,int>>>;
int main(){
	int n,m,p,q,t;
	cin>>n>>m>>p>>q>>t;
	--p;--q;
	G v(n);
	rep(i,m){
		int a,b,c;
		cin>>a>>b>>c;
		--a;--b;
		v[a].emplace_back(c,b);
		v[b].emplace_back(c,a);
	}
	ll dist[n][n];
	rep(i,n)rep(j,n)dist[i][j]=longinf;
	rep(i,n){
		dist[i][i]=0;
		priority_queue<pair<ll,int>> que;
		que.emplace(0,i);
		while(que.size()){
			ll d=-que.top().first;
			int cur=que.top().second;
			que.pop();
			if(d>dist[i][cur])continue;
			for(auto e : v[cur]){
				if(dist[i][e.second]>d+e.first){
					dist[i][e.second]=d+e.first;
					que.emplace(-dist[i][e.second],e.second);
				}
			}
		}
	}
	ll ans=-1;
	ll ret=dist[0][p]+dist[p][q]+dist[q][0];
	if(ret<=t){
		cout<<t<<endl;
		return 0;
	}
	rep(i,n)rep(j,n){
		ll ret1=dist[0][i]+dist[i][p]+dist[p][j]+dist[j][0];
		ll ret2=dist[0][i]+dist[i][q]+dist[q][j]+dist[j][0];
		ll ret=max(ret1,ret2);
		if(ret<=t){
			ans=max(ans,t-ret+dist[0][i]+dist[j][0]);
		}
	}
	cout<<ans<<endl;
	return 0;
}
0