# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1007871 |
2024-06-25T16:04:15 Z |
phong |
Olympic Bus (JOI20_ho_t4) |
C++17 |
|
32 ms |
5832 KB |
#include<bits/stdc++.h>
#define ll long long
#define int long long
const int nmax = 200 + 5, N = 3e5 + 5;
const ll oo = 1e18;
const int lg = 7, M = 4e3;
const int base = 2e5, mod = 998244353;
#define pii pair<ll, ll>
#define fi first
#define se second
#define endl "\n"
#define debug(a, n) for(int i = 1; i <= n; ++i) cout << a[i] << ' ';cout << endl
using namespace std;
multiset<pii> adj[nmax];
struct node{
int u, v, c, d;
}a[N];
ll f[nmax][nmax];
int n, m;
priority_queue<pii, vector<pii>, greater<pii>> q;
ll dp[nmax];
ll dist(int x){
for(int i = 1; i <= n; ++i) dp[i] = oo;
q.push({0, x});
dp[x] =0;
while(q.size()){
pii tmp = q.top();q.pop();
int u = tmp.se;
ll val = tmp.fi;
if(val != dp[u]) continue;
for(auto [v, w] : adj[u]){
if(dp[v] > dp[u] + w){
dp[v] = dp[u] + w;
q.push({dp[v], v});
}
}
}
if(x == 1) return dp[n];
return dp[1];
}
main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// freopen("code.inp", "r", stdin);
// freopen("code.out", "w", stdout);
cin >> n >> m;
memset(f, 0x3f, sizeof f);
for(int i = 1; i <= n; ++i) f[i][i] =0;
for(int i = 1; i <= m; ++i){
int u, v, c, d;
cin >> u >> v >> c >> d;
a[i] = {u, v, c, d};
adj[u].insert({v, c});
f[u][v] = min(f[u][v], 1ll*c);
}
for(int k = 1; k <= n; ++k){
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j){
f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
}
}
}
ll ans = f[1][n] + f[n][1];
for(int i = 1; i <= m; ++i){
int u = a[i].v, v = a[i].u;
ll c1 = min(f[1][n], f[1][u] + f[v][n] + a[i].c) + f[n][1] + a[i].d;
ll c2 = f[1][n]+ min(f[n][1], f[n][u] + f[v][1] + a[i].c) + a[i].d;
ll cur = min(c1, c2);
// cout << cur << ' ';
if(cur >= ans) continue;
swap(u, v);
adj[u].erase(adj[u].find({v, a[i].c}));
adj[v].insert({u, a[i].c});
ans = min(ans, dist(1) + dist(n) + a[i].d);
swap(u, v);
adj[u].erase(adj[u].find({v, a[i].c}));
adj[v].insert({u, a[i].c});
}
if(ans >= oo / 2) cout << -1;
else cout << ans;
}
/*
3 1
4 1 1
5 2 2
*/
Compilation message
ho_t4.cpp:44:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
44 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2652 KB |
Output is correct |
2 |
Correct |
7 ms |
2712 KB |
Output is correct |
3 |
Correct |
7 ms |
2760 KB |
Output is correct |
4 |
Correct |
7 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
7 ms |
2720 KB |
Output is correct |
7 |
Correct |
0 ms |
2652 KB |
Output is correct |
8 |
Correct |
0 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
10 ms |
2764 KB |
Output is correct |
11 |
Correct |
17 ms |
2652 KB |
Output is correct |
12 |
Correct |
7 ms |
2768 KB |
Output is correct |
13 |
Incorrect |
7 ms |
2652 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
5724 KB |
Output is correct |
2 |
Correct |
28 ms |
5712 KB |
Output is correct |
3 |
Correct |
24 ms |
5724 KB |
Output is correct |
4 |
Correct |
7 ms |
2652 KB |
Output is correct |
5 |
Correct |
7 ms |
2652 KB |
Output is correct |
6 |
Correct |
7 ms |
2652 KB |
Output is correct |
7 |
Correct |
7 ms |
2720 KB |
Output is correct |
8 |
Correct |
1 ms |
2648 KB |
Output is correct |
9 |
Incorrect |
32 ms |
5708 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2652 KB |
Output is correct |
2 |
Correct |
10 ms |
2720 KB |
Output is correct |
3 |
Correct |
22 ms |
4956 KB |
Output is correct |
4 |
Correct |
9 ms |
2652 KB |
Output is correct |
5 |
Correct |
26 ms |
5832 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
0 ms |
2652 KB |
Output is correct |
8 |
Incorrect |
27 ms |
5828 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2652 KB |
Output is correct |
2 |
Correct |
7 ms |
2712 KB |
Output is correct |
3 |
Correct |
7 ms |
2760 KB |
Output is correct |
4 |
Correct |
7 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
7 ms |
2720 KB |
Output is correct |
7 |
Correct |
0 ms |
2652 KB |
Output is correct |
8 |
Correct |
0 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
10 ms |
2764 KB |
Output is correct |
11 |
Correct |
17 ms |
2652 KB |
Output is correct |
12 |
Correct |
7 ms |
2768 KB |
Output is correct |
13 |
Incorrect |
7 ms |
2652 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |