結果

問題 No.848 なかよし旅行
ユーザー A8pfA8pf
提出日時 2019-07-22 13:06:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,308 bytes
コンパイル時間 780 ms
コンパイル使用メモリ 84,200 KB
実行使用メモリ 10,756 KB
最終ジャッジ日時 2024-04-16 09:35:08
合計ジャッジ時間 2,924 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
class Edge
{
	public:
	int to;
	ll cost;
	Edge(int t,ll c)
	{
		to=t;
		cost=c;
	}
};

vector<Edge> g[2000];
ll d[3][2000];//0...0から 1...pから 2...qから

void dijk(int s,int n,int mode)
{
	priority_queue<P,vector<P>,greater<P>> q;
	d[mode][s]=0;
	q.push(P(0,s));
	while(!q.empty())
	{
		P p=q.top();q.pop();
		if(p.first>d[mode][p.second])
			continue;
		for(int i=0;i<g[p.second].size();i++)
		{
			Edge e=g[p.second][i];
			if(p.first+e.cost<d[mode][e.to])
			{
				d[mode][e.to]=p.first+e.cost;
				q.push(P(d[mode][e.to],e.to));
			}
		}
	}
	return;
}
int main()
{
	int n,m,p,q,t;
	ll ans=-1;
	cin>>n>>m>>p>>q>>t;
	p--;q--;
	fill(d[0],d[3],1e15-1);
	for(int i=0;i<m;i++)
	{
		int a,b,c;
		cin>>a>>b>>c;
		a--;b--;
		g[a].push_back(Edge(b,c));
		g[b].push_back(Edge(a,c));
	}
	dijk(0,n,0);
	dijk(p,n,1);
	dijk(q,n,2);
	
	//中間ノードの位置を全探索
	for(int i=0;i<n;i++)
	{
		if((d[0][i]+max(d[1][i],d[2][i]))*2>t)
			continue;
		ans=max(t-max(d[1][i],d[2][i])*2,ans);
	}
	//全部通って間に合う場合を考える
	if(min(d[0][p]+d[1][q]+d[2][0],d[0][q]+d[2][p]+d[1][0])<=t)
		ans=t;
	cout<<ans<<endl;
	return 0;
}
0