Submission #1345595

#TimeUsernameProblemLanguageResultExecution timeMemory
1345595po_rag526Commuter Pass (JOI18_commuter_pass)C++20
15 / 100
370 ms54844 KiB
#include<bits/stdc++.h>
#define ll long long
#define vl vector<ll>
#define pb push_back
#define sz(v) (ll)(v.size())
#define f first
#define s second
#define pll pair<ll, ll>
using namespace std;
const ll sz = 2e5+5;
vector<pll>g[sz];
ll vis[sz], dist[sz], par[sz];
void dijkstra(ll node, ll n)
{
    for(ll i = 0; i <= n; i++){
        dist[i] = 1000000000000000;
        vis[i] = 0;
    }
    dist[node] = 0;
    priority_queue<pll>pq;
    pq.push({0, node});
    while(!pq.empty())
    {
        ll nd = pq.top().s;
        pq.pop();
        if(vis[nd])
            continue;
        vis[nd] = 1;
        for(auto [u, w] : g[nd])
        {
            if(dist[u] > dist[nd] + w)
            {
                dist[u] = dist[nd] + w;
                par[u] = nd;
                pq.push({-dist[u], u});
            }
        }
    }
}
void solve()
{
    ll n, m, i, j;
    cin >> n >> m;
    ll s, t, u, v;
    cin >> s >> t;
    cin >> u >> v;
    map<pll, ll>mp;
    for(i = 1; i <= m; i++)
    {
        ll x, y, z;
        cin >> x >> y >> z;
        mp[{x, y}] = z;
        mp[{y, x}] = z;
        g[x].pb({y, z});
        g[y].pb({x, z});
    }
    dijkstra(s, n);
    ll f = t;
    while(f != s)
    {
        mp[{f, par[f]}] = 0;
        mp[{par[f], f}] = 0;
        f = par[f];
    }
    for(i = 1; i <= n; i++)
        g[i].clear();
    for(auto u : mp){
        g[u.f.f].pb({u.f.s, u.s});
        g[u.f.s].pb({u.f.f, u.s});
    }
    dijkstra(u, n);
    cout << dist[v] << "\n";
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tests = 1;
    //cin >> tests;
    while(tests--)
    {
        solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...