結果

問題 No.1 道のショートカット
ユーザー tkzw_21tkzw_21
提出日時 2015-01-28 21:10:58
言語 C++11
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,530 bytes
コンパイル時間 1,778 ms
コンパイル使用メモリ 158,504 KB
実行使用メモリ 204,692 KB
最終ジャッジ日時 2023-09-22 11:52:46
合計ジャッジ時間 8,666 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 6 ms
4,376 KB
testcase_11 TLE -
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 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

typedef pair<int,int> P;
typedef pair<int,pair<int,int>> PP;
typedef long long LL;

const double EPS = 1e-8;
const int INF = 1e9;

int dy[] = {0,1,0,-1};
int dx[] = {1,0,-1,0};

struct edge{
	int to,cost,tm;
};

int used[51];

int bfs(vector<vector<edge>>& es,int C,int G){
	//時間、コスト、どこにいるか
	priority_queue<PP,vector<PP>,greater<PP>> pq;
	pq.push(make_pair(0,make_pair(C,0)));
	used[0] = 1;

	int ret = INF;
	while(!pq.empty()){
		PP pp = pq.top();pq.pop();
		if(pp.second.second == G)ret = min(ret,pp.first);

		for(int i=0;i<es[pp.second.second].size();i++){
			int v = es[pp.second.second][i].to;
			int c = pp.second.first - es[pp.second.second][i].cost;
			int tm = pp.first + es[pp.second.second][i].tm;

			if( c < 0)continue;
			pq.push(make_pair(tm,make_pair(c,v)));
			used[v] = 1;
		}
	}
	return ret==INF ? -1 : ret;
}

int main(void) {
	int N,C,V;
	vector<vector<edge>>es;
	cin >> N >> C >> V;
	es.resize(N);

	vector<int> S(V),T(V),Y(V),M(V);
	for(int i=0;i<V;i++)cin >> S[i];
	for(int i=0;i<V;i++)cin >> T[i];
	for(int i=0;i<V;i++)cin >> Y[i];
	for(int i=0;i<V;i++)cin >> M[i];
	for(int i=0;i<V;i++)es[S[i]-1].push_back(edge{T[i]-1,Y[i],M[i]});

	cout << bfs(es,C,N-1) << endl;

	return 0;
}

// command shift d duplicate
// command ctrl up down
// command D
// command caps G → '' ""
// vector<vector<int>> a(N,vector<int>(M,-1));
//diff < (./a.out < input.txt) output.txt
// sort(v.begin(),v.end(),greater<int>());
0