This commit is contained in:
unlockable
2024-01-20 21:43:24 +01:00
parent 56f1758c36
commit 4b899fb305
2 changed files with 68 additions and 0 deletions

2
2023209/input.txt Normal file
View File

@@ -0,0 +1,2 @@
4 5 0 1 1 1 0 2 4 2 1 2 1 5 1 3 4 2 2 3 1 1 0 3 4
4 5 0 1 1 1 1 2 1 5 1 3 4 2 2 0 4 2 2 3 1 1 0 3 4

66
2023209/main.cpp Normal file
View File

@@ -0,0 +1,66 @@
#include <stdio.h>
int N, M;
unsigned short edges[1050000][3] = {0};
// 边是否顺序? 按开始点排序
// 时间限制最大是多少? 超过unsigned short
int head[66000] = {0};
unsigned short start = 0, terminal = 0;
int time_limit = 0;
int path[1000] = {0};
int current_cheap = 2147483647;
int dfs(unsigned short cur, int cur_time, int cur_cost, int path_ptr) {
path[path_ptr] = cur;
if (cur_time > time_limit) {
return 0;
}
if (cur_cost > current_cheap) {
return 0;
}
if (cur == terminal) {
if (cur_cost < current_cheap) {
current_cheap = cur_cost;
}
return 0;
}
for (int i = head[cur]; i < head[cur + 1]; i++) {
for (int j = 0; j < path_ptr; j++) {
if (path[j] == edges[i][0]) {
continue;
}
}
dfs(edges[i][0], cur_time + edges[i][1], cur_cost + edges[i][2], path_ptr + 1);
}
return 0;
}
int main() {
scanf("%d %d", &N, &M);
head[0] = 0;
int next_empty_edge = 0;
int current_start = 0;
for (int i = 0; i < M; i++) {
int from, to, time, cost;
scanf("%d %d %d %d", &from, &to, &time, &cost);
if (from != current_start) {
for (int j = current_start + 1; j <= from; j++) {
head[j] = next_empty_edge;
}
current_start = from;
// head[from] = next_empty_edge;
}
edges[next_empty_edge][0] = to;
edges[next_empty_edge][1] = time;
edges[next_empty_edge][2] = cost;
next_empty_edge++;
}
head[++current_start] = next_empty_edge;
scanf("%hu %hu %d", &start, &terminal, &time_limit);
dfs(start, 0, 0, 0);
printf("%d\n", current_cheap);
return 0;
}