結果

問題 No.1 道のショートカット
ユーザー OnjuOnju
提出日時 2015-01-30 03:15:44
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 956 bytes
コンパイル時間 578 ms
コンパイル使用メモリ 60,716 KB
実行使用メモリ 7,828 KB
最終ジャッジ日時 2023-09-22 11:53:54
合計ジャッジ時間 7,211 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
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 #

//No.1 道のショートカット

//メモ:
//  有効グラフの閉路はない
//  無効グラフの閉路はある

#include <iostream>
#include <vector>
#define V_MAX 1500
using namespace std;

int N, C, V;
int S[V_MAX], T[V_MAX], Y[V_MAX], M[V_MAX];

typedef struct
{
	int Y;
	int M;
} YM;

YM solve(int p, YM ym)
{
	if (p == N)
		return ym;

	YM ans = YM{ -1, -1 };
	vector<YM> vec;

	for (int i = 0; i < V; ++i)
	{
		if (S[i] == p)
		{
			YM temp = solve(T[i], YM{ ym.Y + Y[i], ym.M + M[i] });
			if (temp.Y <= C)
				vec.push_back(temp);
		}
	}

	vector<YM>::iterator it = vec.begin();
	for (; it != vec.end(); ++it)
	{	
		if (ans.M < 0 || (*it).M < ans.M)
			ans = (*it);
	}

	return ans;
}

int main()
{
	//N,C,V取得
	cin >> N >> C >> V;

	//S,T,Y,M取得
	int* D[4] = { S, T, Y, M };
	for (int di = 0; di < 4; ++di)
		for (int i = 0; i < V; ++i)
			cin >> D[di][i];

	//結果出力
	cout << solve(1, YM{ 0, 0 }).M << endl;

	return 0;
}
0