#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (int)1e18
#define endl '\n'
const int mod = 1000 * 1000 * 1000 + 7;
const int N = 100005;
#define f first
#define s second
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define rrep(i, a, b) for(int i = (a); i > (b); i--)
#define vi vector<int>
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
/*
*/
struct node{
int u , v , c , d;
};
void Solve() {
int n , m; cin>>n>>m;
vector<node> edge(m);
for (int i = 0; i < m ; ++i) {
cin>>edge[i].u>>edge[i].v>>edge[i].c>>edge[i].d;
}
vector<vector<int> > dis(n+1,vector<int> (n+1,1e18));
for(auto &i : edge){
dis[i.u][i.v] = min(dis[i.u][i.v], i.c);
}
for(int k = 1 ; k <= n ; k++){
for(int i = 1 ; i <= n ; i++){
for(int j = 1 ; j <= n ; j++){
dis[i][j] = min(dis[i][j] , dis[i][k] + dis[k][j]);
}
}
}
int ans = dp[1][n] + dp[n][1];
for(auto &i : edge){
//orginal u - > v , now its 1 .. v -> u > .. n
ans = min(ans , dis[1][i.v] + dis[i.u][n] + i.c + i.d+ dis[n][i.u] + dis[i.v][1] + i.c );
}
cout<< ans << endl;
}
int32_t main() {
auto begin = std::chrono::high_resolution_clock::now();
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
//cout << "Case #" << i << ": ";
Solve();
}
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";
return 0;
Compilation message
ho_t4.cpp: In function 'void Solve()':
ho_t4.cpp:46:15: error: 'dp' was not declared in this scope
46 | int ans = dp[1][n] + dp[n][1];
| ^~
ho_t4.cpp: In function 'int32_t main()':
ho_t4.cpp:69:13: error: expected '}' at end of input
69 | return 0;
| ^
ho_t4.cpp:54:16: note: to match this '{'
54 | int32_t main() {
| ^