Submission #1167679

#TimeUsernameProblemLanguageResultExecution timeMemory
1167679herissonwowCommuter Pass (JOI18_commuter_pass)C++20
0 / 100
203 ms14632 KiB
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#define ll long long
#define ld long double
#define en exit(0);
#define pb push_back
#define fi first
#define se second

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e5+5;
const ll INF = 1e18+5;
vector<pair<int,int> > g[N];
bool marked[N];
vector<ll> dijkstra(int st, int n)
{
    vector<ll> dist(n+1,INF);
    vector<bool> vis(n+1);
    priority_queue<pair<ll,int> > q;
    dist[st]=0;
    q.push({0,st});
    while(!q.empty())
    {
        int u = q.top().se;
        q.pop();
        if(vis[u])
            continue;
        vis[u]=1;
        for(auto p:g[u])
        {
            ll nwd = dist[u]+p.se;
            if(nwd<dist[p.fi])
            {
                dist[p.fi]=nwd;
                q.push({-nwd,p.fi});
            }
        }
    }
    return dist;
}

int main()
{
    //ios_base()::sync_with_stdio(false); cin.tie(0);
    int n, m, s, t, u, v; cin >> n >> m >> s >> t >> u >> v;

    for(int i = 0; i < m; i++){
        int a, b, c; cin >> a >> b >> c;
        g[a].push_back({b,c});
        g[b].push_back({a,c});
    }
    vector <long long> dS = dijkstra(s, n);
    vector <long long> dT = dijkstra(t, n);
    vector <long long> dV = dijkstra(v, n);
    int TOT = dS[t];
    for(int i = 1; i <= n; i++){
        if(dS[i]+dT[i]==TOT)
                marked[i]=1;
    }
    ll res = INF;
    for(int i = 1; i <= n; i++){
        if(marked[i]){
            res = min(res, dV[i]);
        }
    }
    cout << res;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...