結果

問題 No.848 なかよし旅行
ユーザー kotatsugamekotatsugame
提出日時 2019-07-07 18:54:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 148 ms / 2,000 ms
コード長 1,248 bytes
コンパイル時間 808 ms
コンパイル使用メモリ 87,380 KB
実行使用メモリ 10,740 KB
最終ジャッジ日時 2023-08-07 19:48:26
合計ジャッジ時間 3,098 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 148 ms
10,740 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 32 ms
5,272 KB
testcase_12 AC 43 ms
5,568 KB
testcase_13 AC 57 ms
6,424 KB
testcase_14 AC 18 ms
4,376 KB
testcase_15 AC 53 ms
6,420 KB
testcase_16 AC 93 ms
8,324 KB
testcase_17 AC 64 ms
7,176 KB
testcase_18 AC 32 ms
5,100 KB
testcase_19 AC 27 ms
4,616 KB
testcase_20 AC 12 ms
4,376 KB
testcase_21 AC 79 ms
7,496 KB
testcase_22 AC 83 ms
7,576 KB
testcase_23 AC 11 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 97 ms
8,228 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:37:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   37 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#include<vector>
#include<queue>
#include<limits>
template<typename T>
vector<T>dijkstra(int s,const vector<vector<pair<int,T> > >&G,T INF=numeric_limits<T>::max())
{
	int n=G.size();
	vector<T>d(n,INF);
	vector<int>parent(n,-1);
	priority_queue<pair<T,int>,vector<pair<T,int> >,greater<pair<T,int> > >P;
	d[s]=0;
	P.push(make_pair(d[s],s));
	while(!P.empty())
	{
		pair<T,int>p=P.top();P.pop();
		int v=p.second;
		if(d[v]<p.first)continue;
		for(const pair<int,T>&e:G[v])
		{
			int u=e.first;
			T cost=d[v]+e.second;
			if(d[u]>cost)
			{
				d[u]=cost;
				parent[u]=v;
				P.push(make_pair(d[u],u));
			}
		}
	}
	return d;
}
int N,M,P,Q,T;
main()
{
	cin>>N>>M>>P>>Q>>T;
	vector<vector<pair<int,long> > >G(N);
	for(int i=0;i<M;i++)
	{
		int a,b,c;cin>>a>>b>>c;
		a--,b--;
		G[a].push_back(make_pair(b,c));
		G[b].push_back(make_pair(a,c));
	}
	P--,Q--;
	vector<long>d1=dijkstra(0,G);
	vector<long>dp=dijkstra(P,G);
	vector<long>dq=dijkstra(Q,G);
	long ans=-1;
	if(d1[P]+dp[Q]+dq[0]<=T)ans=T;
	for(int i=0;i<N;i++)for(int j=0;j<N;j++)
	{
		if(d1[i]+max(dp[i]+dp[j],dq[i]+dq[j])+d1[j]<=T)
		{
			ans=max(ans,T-max(dp[i]+dp[j],dq[i]+dq[j]));
		}
	}
	cout<<ans<<endl;
}
0