#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, 1e18)), chn(n+1, vll(n+1, 1e18)), dist(n+1, vll(n+1, 1e18));
forr(i, 1, n+1) 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);
}
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] + 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] + 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] + cost[p.f][p.s] + chn[p.f][p.s];
// printf("%lld\n", v);
mi = min(mi, v);
}
printf("%lld", mi);
}
Compilation message
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);
| ^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
1628 KB |
Output is correct |
2 |
Incorrect |
7 ms |
1372 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
2008 KB |
Output is correct |
2 |
Correct |
21 ms |
2776 KB |
Output is correct |
3 |
Correct |
22 ms |
3032 KB |
Output is correct |
4 |
Correct |
8 ms |
1372 KB |
Output is correct |
5 |
Correct |
7 ms |
1372 KB |
Output is correct |
6 |
Incorrect |
7 ms |
1368 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
1372 KB |
Output is correct |
2 |
Incorrect |
8 ms |
1400 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
1628 KB |
Output is correct |
2 |
Incorrect |
7 ms |
1372 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |