結果

問題 No.848 なかよし旅行
ユーザー 👑 kmjpkmjp
提出日時 2019-07-05 21:51:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 1,510 bytes
コンパイル時間 1,804 ms
コンパイル使用メモリ 175,144 KB
実行使用メモリ 9,968 KB
最終ジャッジ日時 2024-04-25 13:47:50
合計ジャッジ時間 3,414 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
9,028 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 3 ms
7,772 KB
testcase_10 AC 3 ms
6,944 KB
testcase_11 AC 19 ms
8,680 KB
testcase_12 AC 23 ms
6,944 KB
testcase_13 AC 30 ms
9,404 KB
testcase_14 AC 14 ms
8,148 KB
testcase_15 AC 29 ms
9,360 KB
testcase_16 AC 46 ms
9,968 KB
testcase_17 AC 32 ms
9,728 KB
testcase_18 AC 18 ms
8,740 KB
testcase_19 AC 18 ms
8,388 KB
testcase_20 AC 11 ms
7,820 KB
testcase_21 AC 38 ms
9,524 KB
testcase_22 AC 35 ms
9,444 KB
testcase_23 AC 10 ms
6,944 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 48 ms
6,944 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M,P,Q,T;
vector<pair<int,int>> E[2020];
ll D[2020][2020];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M>>P>>Q>>T;
	P--,Q--;
	FOR(i,M) {
		cin>>x>>y>>r;
		x--,y--;
		E[x].push_back({y,r});
		E[y].push_back({x,r});
	}
	priority_queue<pair<ll,int>> PQ;
	FOR(i,N) {
		if(i!=0 && i!=P && i!=Q) continue;
		FOR(j,N) D[i][j]=1LL<<60;
		D[i][i]=0;
		PQ.push({0,i});
		while(PQ.size()) {
			ll co=-PQ.top().first;
			int cur=PQ.top().second;
			PQ.pop();
			if(D[i][cur]!=co) continue;
			FORR(e,E[cur]) {
				if(D[i][e.first]>co+e.second) {
					D[i][e.first]=co+e.second;
					PQ.push({-D[i][e.first],e.first});
				}
			}
		}
	}
	
	ll ma=-1;
	FOR(x,N) FOR(y,N) {
		ll a=D[0][x]+D[0][y];
		ll b=max(D[P][x]+D[P][y],D[Q][x]+D[Q][y]);
		if(a+b<=T) ma=max(ma,T-b);
	}
	if(D[0][P]+D[P][Q]+D[Q][0]<=T) ma=T;
	cout<<ma<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0