// #pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")
// #include <bits/extc++.h>
// using namespace __gnu_pbds;
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;
#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back
#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
mt19937 __gen = mt19937(__rd()); \
uniform_int_distribution<int> __dis(1, 1E8); \
auto rnd = bind(__dis, __gen)
const int INF = 1E18;
const int mod = 1E9 + 7;
const int maxn = 200 + 5;
struct Edge {
int u, v, c, d;
Edge(int _u = 0, int _v = 0, int _c = 0, int _d = 0) :
u(_u), v(_v), c(_c), d(_d) {}
};
vector<Edge> edge;
int floyd[maxn][maxn];
void init() {
for (int i = 0; i < maxn; ++i) {
for (int j = 0; j < maxn; ++j) floyd[i][j] = INF;
floyd[i][i] = 0;
}
}
int32_t main() {
fastIO();
init();
int n, m;
cin >> n >> m;
for (int i = 0; i < m; ++i) {
int u, v, c, d;
cin >> u >> v >> c >> d;
edge.eb(u, v, c, d);
floyd[u][v] = min(floyd[u][v], c);
}
for (int mid = 1; mid <= n; ++mid) {
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
floyd[i][j] = min(floyd[i][j], floyd[i][mid] + floyd[mid][j]);
}
}
}
/* if (floyd[1][n] != INF and floyd[n][1] == INF) {
int minC = INF;
for (auto e : edge) {
// if (floyd[e.u][1] != INF and floyd[n][e.v] != INF) //
minC = min(minC, floyd[e.u][1] + floyd[n][e.v] + e.c + e.d);
}
cout << (minC == INF ? -1 : minC + floyd[1][n]) << "\n";
return 0;
} */
int minC = floyd[1][n] + floyd[n][1];
for (auto e : edge) {
int min1N = min(floyd[1][n], floyd[e.u][n] + floyd[1][e.v] + e.c);
int minN1 = min(floyd[n][1], floyd[e.u][1] + floyd[n][e.v] + e.c);
// cout << min1N << " " << minN1 << " " << e.d << " " << min1N + minN1 + e.d << "\n";
minC = min(minC, min1N + minN1 + e.d);
}
cout << (minC >= INF ? -1 : minC) << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
768 KB |
Output is correct |
2 |
Correct |
13 ms |
640 KB |
Output is correct |
3 |
Correct |
13 ms |
768 KB |
Output is correct |
4 |
Correct |
15 ms |
768 KB |
Output is correct |
5 |
Correct |
5 ms |
768 KB |
Output is correct |
6 |
Correct |
13 ms |
768 KB |
Output is correct |
7 |
Incorrect |
5 ms |
640 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
2936 KB |
Output is correct |
2 |
Correct |
35 ms |
3704 KB |
Output is correct |
3 |
Correct |
36 ms |
3832 KB |
Output is correct |
4 |
Correct |
14 ms |
896 KB |
Output is correct |
5 |
Correct |
13 ms |
768 KB |
Output is correct |
6 |
Correct |
13 ms |
788 KB |
Output is correct |
7 |
Correct |
13 ms |
768 KB |
Output is correct |
8 |
Correct |
5 ms |
640 KB |
Output is correct |
9 |
Correct |
36 ms |
3832 KB |
Output is correct |
10 |
Correct |
36 ms |
3960 KB |
Output is correct |
11 |
Correct |
35 ms |
3952 KB |
Output is correct |
12 |
Correct |
34 ms |
3832 KB |
Output is correct |
13 |
Correct |
35 ms |
3832 KB |
Output is correct |
14 |
Correct |
36 ms |
3832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
768 KB |
Output is correct |
2 |
Correct |
13 ms |
640 KB |
Output is correct |
3 |
Correct |
30 ms |
3576 KB |
Output is correct |
4 |
Correct |
13 ms |
640 KB |
Output is correct |
5 |
Correct |
34 ms |
3576 KB |
Output is correct |
6 |
Incorrect |
5 ms |
640 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
768 KB |
Output is correct |
2 |
Correct |
13 ms |
640 KB |
Output is correct |
3 |
Correct |
13 ms |
768 KB |
Output is correct |
4 |
Correct |
15 ms |
768 KB |
Output is correct |
5 |
Correct |
5 ms |
768 KB |
Output is correct |
6 |
Correct |
13 ms |
768 KB |
Output is correct |
7 |
Incorrect |
5 ms |
640 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |