Submission #1181969

#TimeUsernameProblemLanguageResultExecution timeMemory
1181969anteknneCommuter Pass (JOI18_commuter_pass)C++20
0 / 100
184 ms22964 KiB
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define st first
#define nd second
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define debug false

const int MAXN = 100 * 1000 + 1;
vector<pil> graf[MAXN];
ll odl[MAXN];
ll odlS[MAXN];
ll odlT[MAXN];
ll odlU[MAXN];
ll odlV[MAXN];
ll dp[MAXN][4];
vector<pli> vec;
priority_queue<pil> pq;

void djikstra (int s) {
    memset(odl, ll(INT_MAX) * ll(MAXN), sizeof(odl));

    /*for (int i = 1; i <= 8; i ++) {
        cout << odl[i] << " ";
    }*/

    odl[s] = 0;
    pq.push({0, s});

    while (!pq.empty()) {
        int v = pq.top().nd;
        ll vodl = -pq.top().st;
        pq.pop();
        if (vodl > odl[v]) {
            continue;
        }
        for (auto x : graf[v]) {
            if (vodl + x.nd < odl[x.st]) {
                odl[x.st] = vodl + x.nd;
                pq.push({-odl[x.st], x.st});
            }
        }
    }
}

int main () {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n, m, S, T, U, V;
    cin >> n >> m >> S >> T >> U >> V;

    int a, b;
    ll c;
    for (int i = 0; i < m; i ++) {
        cin >> a >> b >> c;
        graf[a].pb({b, c});
        graf[b].pb({a, c});
    }

    djikstra(S);
    swap(odl, odlS);
    djikstra(T);
    swap(odl, odlT);
    djikstra(U);
    swap(odl, odlU);
    djikstra(V);
    swap(odl, odlV);

    if (debug) {
        cout << "odlS:\n";
        for (int i = 1; i <= n; i ++) {
            cout << i << ": " << odlS[i] << "\n";
        }
        cout << "\n";
    }

    for (int i = 1; i <= n; i ++) {
        vec.pb({odlS[i], i});
    }

    sort(vec.begin(), vec.end());

    memset(dp, ll(INT_MAX) * ll(MAXN), sizeof(dp));
    dp[S][0] = 0;
    dp[S][1] = odlU[S];
    dp[S][2] = odlV[S];
    dp[S][3] = odlU[S] + odlV[S];

    for (auto x : vec) {
        int v = x.nd;
        for (auto x : graf[v]) {
            if (odlS[v] == odlS[x.st] + x.nd) {
                for (int i = 0; i < 4; i ++) {
                    for (int j = 0; j < 4; j ++) {
                        ll dod = 0;
                        if (j & 1) {
                            dod += odlU[x.st];
                        }
                        if (j & 2) {
                            dod += odlV[x.st];
                        }
                        dp[v][i | j] = min(dp[v][i | j], dp[x.st][i] + dod);
                    }
                }
            }
        }
    }

    cout << min(dp[T][3], odlU[V]) << "\n";



    return 0;
}

Compilation message (stderr)

commuter_pass.cpp: In function 'void djikstra(int)':
commuter_pass.cpp:33:29: warning: overflow in conversion from 'll' {aka 'long long int'} to 'int' changes value from '214750512183647' to '2147383647' [-Woverflow]
   33 |     memset(odl, ll(INT_MAX) * ll(MAXN), sizeof(odl));
      |                 ~~~~~~~~~~~~^~~~~~~~~~
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:95:28: warning: overflow in conversion from 'll' {aka 'long long int'} to 'int' changes value from '214750512183647' to '2147383647' [-Woverflow]
   95 |     memset(dp, ll(INT_MAX) * ll(MAXN), sizeof(dp));
      |                ~~~~~~~~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...