結果

問題 No.1 道のショートカット
ユーザー iwashi31
提出日時 2014-11-19 00:34:21
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,115 bytes
コンパイル時間 871 ms
コンパイル使用メモリ 84,380 KB
実行使用メモリ 800,412 KB
最終ジャッジ日時 2024-07-08 03:35:48
合計ジャッジ時間 7,467 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7 MLE * 1 -- * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <deque>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>

using namespace std;

struct S_load {
	int pnext;
	int cost;
	int time;
};

class C_node {
public:
	long int scost;
	long int stime;
	bool operator<(const C_node& arg) const {
		if (this->stime < arg.stime) return true;
		if (this->stime > arg.stime) return false;
		if (this->scost > arg.scost) return false;
		return true;
	}
};

int N, C, V;
int S[1510], T[1510], Y[1510], M[1510];
bool qflag[1510];
vector<S_load> pnext[1510];
set<C_node> node[1510];
queue<int> ready;

int main() {
	int i;

	// input
	cin >> N;
	cin >> C;
	cin >> V;
	for (i = 0; i < V; i++) cin >> S[i];
	for (i = 0; i < V; i++) cin >> T[i];
	for (i = 0; i < V; i++) cin >> Y[i];
	for (i = 0; i < V; i++) cin >> M[i];

	for (i = 0; i < V; i++) {
		S_load tempload;
		tempload.pnext = T[i];
		tempload.cost = Y[i];
		tempload.time = M[i];
		pnext[S[i]].push_back(tempload);
	}
	for (i = 1; i <= N; i++) qflag[i] = false;

	// implement
	ready.push(1);
	C_node tempnode;
	tempnode.scost = C;
	tempnode.stime = 0;
	node[1].insert(tempnode);

	while (!ready.empty()) {

		int now = ready.front(); ready.pop();

		if (now == N) continue;

		qflag[now] = false;
		vector<S_load>::iterator it;

		for (it = pnext[now].begin(); it != pnext[now].end(); it++) {

			set<C_node>::iterator itc;

			for (itc = node[now].begin(); itc != node[now].end(); itc++) {

				C_node tempnode;
				tempnode.scost = (*itc).scost - (*it).cost;

				if (tempnode.scost >= 0) {
					tempnode.stime = (*itc).stime + (*it).time;
					node[(*it).pnext].insert(tempnode);
					if (!qflag[(*it).pnext]) {
						qflag[(*it).pnext] = true;
						ready.push((*it).pnext);
					}
				}

			}

		}
		node[now].clear();
	}

	if (!node[N].empty()) {
		set<C_node>::iterator it = node[N].begin();
		cout << (*it).stime << endl;
	} else {
		cout << "-1" << endl;
	}

	return 0;
}
0