This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define scd(x) scanf("%d", &x)
#define sclld(x) scanf("%lld", &x)
#define frange(i, n) for(int i=0; i<n; i++)
#define forr(i, l, r) for(int i=l; i<r; i++)
#define all(vec) vec.begin(), vec.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long lli;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<lli> vll;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef set<int> seti;
void usaco() {
freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
}
int main() {
// usaco();
int n, m;
scd(n);
scd(m);
vector<vll> cost(n+1, vll(n+1, 1e17)), chn(n+1, vll(n+1, 1e17)), dist(n+1, vll(n+1, 1e17));
forr(i, 1, n+1) cost[i][i] = dist[i][i] = 0;
vii edg;
frange(i, m) {
int u, v;
lli c, d;
scd(u);
scd(v);
sclld(c);
sclld(d);
// if(i%2==0)
edg.pb(mp(u, v));
dist[u][v] = cost[u][v] = min(c, cost[u][v]);
chn[u][v] = min(chn[u][v], d);
}
frange(_, 3) {forr(k, 1, n+1) {
forr(i, 1, n+1) {
forr(j, 1, n+1) {
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}
}
}}
lli mi = dist[1][n] + dist[n][1];
// printf("%lld\n", mi);
for(auto p : edg) {
// printf("%d %d ", p.f, p.s);
lli v = 0;
v = dist[1][n] + dist[n][p.s] + dist[p.f][1] + min(dist[p.s][p.f], cost[p.f][p.s] + chn[p.f][p.s]);
// printf("%lld ", v);
mi = min(mi, v);
v = dist[1][p.s] + dist[p.f][n] + dist[n][p.s] + dist[p.f][1] + min(2*dist[p.s][p.f], 2*cost[p.f][p.s] + chn[p.f][p.s]);
// printf("%lld ", v);
mi = min(mi, v);
v = dist[1][p.s] + dist[p.f][n] + dist[n][1] + min(dist[p.s][p.f], cost[p.f][p.s] + chn[p.f][p.s]);
// printf("%lld\n", v);
mi = min(mi, v);
}
if(mi < 1e16)
printf("%lld", mi);
else printf("-1");
}
Compilation message (stderr)
ho_t4.cpp: In function 'void usaco()':
ho_t4.cpp:25:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t4.cpp: In function 'int main()':
ho_t4.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(x) scanf("%d", &x)
| ~~~~~^~~~~~~~~~
ho_t4.cpp:31:2: note: in expansion of macro 'scd'
31 | scd(n);
| ^~~
ho_t4.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(x) scanf("%d", &x)
| ~~~~~^~~~~~~~~~
ho_t4.cpp:32:2: note: in expansion of macro 'scd'
32 | scd(m);
| ^~~
ho_t4.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(x) scanf("%d", &x)
| ~~~~~^~~~~~~~~~
ho_t4.cpp:42:3: note: in expansion of macro 'scd'
42 | scd(u);
| ^~~
ho_t4.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(x) scanf("%d", &x)
| ~~~~~^~~~~~~~~~
ho_t4.cpp:43:3: note: in expansion of macro 'scd'
43 | scd(v);
| ^~~
ho_t4.cpp:6:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
6 | #define sclld(x) scanf("%lld", &x)
| ~~~~~^~~~~~~~~~~~
ho_t4.cpp:44:3: note: in expansion of macro 'sclld'
44 | sclld(c);
| ^~~~~
ho_t4.cpp:6:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
6 | #define sclld(x) scanf("%lld", &x)
| ~~~~~^~~~~~~~~~~~
ho_t4.cpp:45:3: note: in expansion of macro 'sclld'
45 | sclld(d);
| ^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |