結果

問題 No.1 道のショートカット
ユーザー opqopq_opqopq_
提出日時 2015-04-29 19:50:18
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,360 bytes
コンパイル時間 450 ms
コンパイル使用メモリ 52,268 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 21:42:57
合計ジャッジ時間 2,073 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;

#define MAX_N 50
#define MAX_V 1500
#define INF 1000000007

struct State {
	int n, c, t;
	bool operator < (const State& r) const {
		return t > r.t;
	}
	State(int x, int y, int z) : n(x), c(y), t(z) {}
};

int N, C, V;
int data[MAX_V][4];
vector<State> edge[MAX_N];
int maxm[MAX_N][2];

int main() {
	scanf("%d%d%d", &N, &C, &V);
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < V; j++) {
			scanf("%d", &data[j][i]);
			if (i < 2) data[j][i]--;
		}
	}
	
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 2; j++) {
			maxm[i][j] = INF;
		}
	}
	
	for (int i = 0; i < V; i++) {
		edge[data[i][0]].emplace_back(data[i][1], data[i][2], data[i][3]);
	}
	
	priority_queue<State> pq;
	maxm[0][0] = maxm[0][1] = 0;
	pq.emplace(0, 0, 0);
	int res = 0;
	while (!pq.empty()) {
		State s = pq.top();
		pq.pop();
		if (s.n == N - 1) {
			res = s.t;
			break;
		}
		if (maxm[s.n][0] < s.c && maxm[s.n][1] < s.t) continue;
		for (State n : edge[s.n]) {
			n.c += s.c, n.t += s.t;
			if (C < n.c) continue;
			if (maxm[n.n][0] < n.c && maxm[n.n][1] < n.t) continue;
			if (maxm[n.n][0] == INF) maxm[n.n][0] = n.c, maxm[n.n][1] = n.t;
			maxm[n.n][0] = max(maxm[n.n][0], n.c);
			maxm[n.n][1] = max(maxm[n.n][1], n.t);
			pq.push(n);
		}
	}
	
	printf("%d\n", res ? res : -1);
	
	return 0;
}

0