Submission #1007870

# Submission time Handle Problem Language Result Execution time Memory
1007870 2024-06-25T15:58:42 Z phong Olympic Bus (JOI20_ho_t4) C++17
0 / 100
29 ms 5724 KB
    #include<bits/stdc++.h>

#define ll long long
const int nmax = 200 + 5, N = 5e4 + 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 u){
    for(int i = 1; i <= n; ++i) dp[i] = oo;
    q.push({0, u});
    dp[u] =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(u == 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:43:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   43 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 860 KB Output is correct
2 Correct 7 ms 604 KB Output is correct
3 Correct 7 ms 904 KB Output is correct
4 Correct 7 ms 860 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 7 ms 604 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 10 ms 860 KB Output is correct
11 Correct 22 ms 896 KB Output is correct
12 Correct 8 ms 856 KB Output is correct
13 Incorrect 7 ms 860 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 5720 KB Output is correct
2 Correct 29 ms 5708 KB Output is correct
3 Correct 26 ms 5712 KB Output is correct
4 Correct 7 ms 860 KB Output is correct
5 Correct 7 ms 896 KB Output is correct
6 Correct 9 ms 604 KB Output is correct
7 Correct 7 ms 844 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Incorrect 28 ms 5724 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 860 KB Output is correct
2 Correct 7 ms 604 KB Output is correct
3 Correct 23 ms 4456 KB Output is correct
4 Correct 7 ms 604 KB Output is correct
5 Correct 27 ms 5468 KB Output is correct
6 Correct 0 ms 600 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Incorrect 29 ms 5628 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 860 KB Output is correct
2 Correct 7 ms 604 KB Output is correct
3 Correct 7 ms 904 KB Output is correct
4 Correct 7 ms 860 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 7 ms 604 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 10 ms 860 KB Output is correct
11 Correct 22 ms 896 KB Output is correct
12 Correct 8 ms 856 KB Output is correct
13 Incorrect 7 ms 860 KB Output isn't correct
14 Halted 0 ms 0 KB -