50分还没改:
#include <cstring>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#define ll long long
#define PII pair<int, int>
#define MSI map<string,int>
#define TLE ios::sync_with_stdio(0),cin.tie(0)
#define mod 1000000007
const int INF = 0x3f3f3f3f;
using namespace std;
int map[505][505] = { 0 };
int w[505][505] = { 0 };
int dp[505][505] = { 0 };
int main() {
TLE;
int n, m;
cin >> n >> m;
memset(map, -1, sizeof(map));
for (int i = 0; i <= n; i++)
for (int j = 0; j <= n; j++)
dp[i][j] = INF;
for (int i = 0; i < m; i++) {
int t, u, v, d;
cin >> t >> u >> v >> d;
map[u][v] = ++t;
if (u != 1) dp[u][v] = min(dp[u][v], t * d + t);
else dp[u][v] = min(dp[u][v], t * d);
}
for (int i = 0; i <= n; i++)
dp[i][i] = 0;
for (int i = n; i >=1; i--) {
for (int j = i; j <= n; j++) {
for (int k = 1; k <= n; k++) {
if (map[i][k] != -1 && map[k][j] != -1) {
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
map[i][j] = 0;
// cout <<i<<" -> "<<j<<" dp: "<< dp[i][j] << endl;
}
}
}
}
cout << dp[1][n] << endl;
}
/*
6 7
1 1 2 3
1 2 3 2
0 1 3 30
0 3 4 20
0 4 5 30
1 3 5 6
1 5 6 2
*/