結果

問題 No.1 道のショートカット
ユーザー kurenai3110kurenai3110
提出日時 2016-09-10 06:36:40
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,142 bytes
コンパイル時間 701 ms
コンパイル使用メモリ 68,864 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-22 12:49:42
合計ジャッジ時間 2,218 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 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 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1 ms
4,380 KB
testcase_16 WA -
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
4,380 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
4,384 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 2 ms
4,380 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 2 ms
4,380 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define MAX_N 51

int N, C, V;

struct Edge {
	int cost, time;
};

Edge E[MAX_N][MAX_N];
int Cos[MAX_N];
int Tim[MAX_N];

void add_edge(int a, int b, int c,int t) {
	E[a][b].cost = c;
	E[a][b].time = t;
}

void dfs() {
	stack<int> stk;
	stk.push(1);
	while (!stk.empty()) {
		int v = stk.top(); stk.pop();
		for (int i = v + 1; i <= N; i++) {
			if (Cos[v] + E[v][i].cost <= C) {
				Cos[i] = Cos[v] + E[v][i].cost;
				Tim[i] = min(Tim[i], Tim[v] + E[v][i].time);
				stk.push(i);
			}
		}
	}
}

int main()
{
	cin >> N >> C >> V;
	vector<int> S(V), T(V), Y(V), M(V);
	rep(i, V)cin >> S[i];
	rep(i, V)cin >> T[i];
	rep(i, V)cin >> Y[i];
	rep(i, V)cin >> M[i];

	for (int i = 1; i < N; i++) {
		for (int j = i + 1; j <= N; j++) {
			E[i][j].cost = INT16_MAX;
		}
	}
	for (int i = 2; i <= N; i++) Tim[i] = INT32_MAX;

	for (int i = 0; i < V; i++) {
		add_edge(S[i], T[i], Y[i], M[i]);
	}

	dfs();

	if (Tim[N] == INT32_MAX)cout << -1 << endl;
	else cout << Tim[N] << endl;

    return 0;
}
0