# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1036801 |
2024-07-27T17:23:08 Z |
juicy |
Olympic Bus (JOI20_ho_t4) |
C++17 |
|
109 ms |
3012 KB |
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 205, M = 5e4 + 5;
const int inf = 5e8;
int n, m;
int pr[N], w[M], d[2][N];
bool spec[M];
vector<array<int, 2>> g[N];
array<int, 3> edges[M];
void dijkstra(int s, int *d) {
using T = array<int, 2>;
priority_queue<T, vector<T>, greater<T>> pq;
fill(d + 1, d + n + 1, inf);
fill(pr + 1, pr + n + 1, 0);
pq.push({d[s] = 0, s});
while (pq.size()) {
auto [c, u] = pq.top(); pq.pop();
if (c != d[u]) {
continue;
}
for (auto [v, id] : g[u]) {
if (d[v] > d[u] + w[id]) {
pr[v] = id;
pq.push({d[v] = d[u] + w[id], v});
}
}
}
}
void mark() {
for (int i = 1; i <= n; ++i) {
spec[pr[i]] = 1;
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= m; ++i) {
int u, v, c; cin >> u >> v >> w[i] >> c;
edges[i] = {u, v, c};
g[u].push_back({v, i});
}
dijkstra(1, d[0]);
mark();
dijkstra(n, d[1]);
mark();
auto del = [&](int u, array<int, 2> x) {
for (auto &v : g[u]) {
if (v == x) {
swap(v, g[u].back());
g[u].pop_back();
break;
}
}
};
auto add = [&](int u, array<int, 2> x) {
g[u].push_back(x);
};
int res = d[0][n] + d[1][1];
for (int i = 1; i <= m; ++i) {
if (spec[i]) {
auto [u, v, c] = edges[i];
del(u, {v, i});
add(v, {u, i});
dijkstra(1, d[0]);
dijkstra(n, d[1]);
res = min(res, d[0][n] + d[1][1] + c);
del(v, {u, i});
add(u, {v, i});
}
}
cout << (res < inf ? res : -1);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
14 ms |
348 KB |
Output is correct |
4 |
Correct |
17 ms |
544 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
3012 KB |
Output is correct |
2 |
Incorrect |
109 ms |
2912 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
56 ms |
2140 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
62 ms |
2892 KB |
Output is correct |
6 |
Correct |
1 ms |
480 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Incorrect |
23 ms |
2640 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
14 ms |
348 KB |
Output is correct |
4 |
Correct |
17 ms |
544 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |