#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define all(x) begin(x), end(x)
using ll = long long;
template<class T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
const int N = 1 << 9, M = 1 << 16;
const ll inf = 1e18;
int n;
ll d[N][N], dist[N];
int a[M], b[M], w[M], c[M];
vector<int> g[N];
bool vis[N];
ll dij(int s, int t) {
fill(dist, dist + n, inf);
fill(vis, vis + n, false);
d[s] = 0;
rep(i, 0, n) {
int u = -1;
rep(v, 0, n) if (!vis[v] && (u == -1 || dist[v] < dist[u])) u = v;
if (u == t) return d[u];
if (d[u] == inf) break;
for (int e : g[u]) ckmin(d[b[e]], d[u] + w[e]);
}
return inf;
}
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int m; cin >> n >> m;
rep(u, 0, n) rep(v, 0, n) d[u][v] = inf;
rep(u, 0, n) d[u][u] = 0;
rep(e, 0, m) {
cin >> a[e] >> b[e] >> w[e] >> c[e], --a[e], --b[e];
ckmin(d[a[e]][b[e]], ll(w[e]));
g[a[e]].push_back(e);
}
rep(w, 0, n) rep(u, 0, n) rep(v, 0, n) ckmin(d[u][v], d[u][w] + d[w][v]);
int s = 0, t = n - 1;
ll ans = d[s][t] + d[t][s];
rep(e, 0, m) {
ll to = min(d[s][t], d[s][b[e]] + w[e] + d[a[e]][t]);
ll fr = min(d[t][s], d[t][b[e]] + w[e] + d[a[e]][s]);
if (c[e] + to + fr < ans) {
g[a[e]].erase(find(all(g[a[e]]), e)); swap(a[e], b[e]); g[a[e]].push_back(e);
ckmin(ans, c[e] + dij(s, t) + dij(t, s));
g[a[e]].pop_back(); swap(a[e], b[e]); g[a[e]].push_back(e);
}
}
cout << (ans < inf ? ans : -1);
}
Compilation message
ho_t3.cpp: In function 'll dij(int, int)':
ho_t3.cpp:24:9: error: incompatible types in assignment of 'int' to 'll [512]' {aka 'long long int [512]'}
24 | d[s] = 0;
| ^
ho_t3.cpp:28:25: error: invalid conversion from 'll*' {aka 'long long int*'} to 'll' {aka 'long long int'} [-fpermissive]
28 | if (u == t) return d[u];
| ~~~^
| |
| ll* {aka long long int*}
ho_t3.cpp:29:15: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
29 | if (d[u] == inf) break;
| ^~~
ho_t3.cpp:30:48: error: no matching function for call to 'ckmin(ll [512], ll*)'
30 | for (int e : g[u]) ckmin(d[b[e]], d[u] + w[e]);
| ^
ho_t3.cpp:9:24: note: candidate: 'template<class T> bool ckmin(T&, const T&)'
9 | template<class T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
| ^~~~~
ho_t3.cpp:9:24: note: template argument deduction/substitution failed:
ho_t3.cpp:30:48: note: deduced conflicting types for parameter 'const T' ('long long int [512]' and 'll*' {aka 'long long int*'})
30 | for (int e : g[u]) ckmin(d[b[e]], d[u] + w[e]);
| ^