## C. Journey bfs 拓扑排序+dp

C. Journey

```#include <cstring>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#define inf 0x3f3f3f3f
#define inx64 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 5e3 + 10;
struct node {
int u, v, w;
node(int u = 0, int v = 0, int w = 0) :u(u), v(v), w(w) {}
};
vector<node>e;
vector<int>G[maxn];
int dp[maxn][maxn], in[maxn];
void add(int u, int v, int w) {
e.push_back(node(u, v, w));
G[u].push_back(e.size() - 1);
in[v]++;
}
int p[5050][5050];
int n, m, t;
void bfs(int s) {
queue<int>que;
for (int i = 1; i <= n; i++) {
if (in[i] == 0) que.push(i);
}
while (!que.empty()) {
int u = que.front(); que.pop();
for (int i = 0; i < G[u].size(); i++) {
node now = e[G[u][i]];
int v = now.v;
for (int j = 1; j <= n; j++) {
if (dp[v][j] > dp[u][j - 1] + now.w) {
dp[v][j] = dp[u][j - 1] + now.w;
p[v][j] = u;
}
}
in[v]--;
if (in[v] == 0) que.push(v);
}
}
}

int b[maxn];

int main() {
scanf("%d%d%d", &n, &m, &t);
while (m--) {
int u, v, w;
scanf("%d%d%d", &u, &v, &w);
}
memset(dp, inf, sizeof(dp));
dp[1][1] = 0;
bfs(1);
int ans = 0;
for (int i = 1; i <= n; i++) if (dp[n][i] <= t) ans = i;
printf("%d\n", ans);
int u = n;
for (int i = ans; i >= 1; i--) {
b[i] = u;
u = p[u][i];
}
for (int i = 1; i <= ans; i++) printf("%d ", b[i]);
printf("\n");
return 0;
}```
dp+拓扑排序