Submission #991319

#TimeUsernameProblemLanguageResultExecution timeMemory
991319mindiyakCommuter Pass (JOI18_commuter_pass)C++14
15 / 100
169 ms26656 KiB
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <cmath>
#include <numeric>
#include <queue>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<int, int> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
#define len(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fst first
#define nl endl
#define sec second
#define lb lower_bound
#define ub upper_bound
#define aint(x) x.begin(), x.end()
#define raint(x) x.rbegin(), x.rend()
#define ins insert
#define INF 1e18
const int MOD = 1000000007;
void init()
{
#ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
    freopen("output.out", "w", stdout);
#endif
}
void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
}

ll n,m,s,t,u,v;
vector<vector<pair<ll,ll>>> paths(1e5+10);
ll ans = 0;
vl connector(1e5+10,-1);

void dijisktra(int s,int t){
    vi visited(1e5+10,0); 
    vector<ll> distance(1e5+10,INF); 
    priority_queue<pair<ll,ll>> pq;
    distance[s] = 0;
    pq.push({0,s});
    while(!pq.empty()){
        ll a = pq.top().sec;pq.pop();
        if(visited[a])continue;
        visited[a] = 1;
        for(auto k:paths[a]){
            ll b = k.fst,c = k.sec;
            if(distance[a]+c<distance[b]){
                distance[b]  = distance[a]+c;
                connector[b] = a;
                pq.push({-distance[b],b});
            }
        }
    }
    ans = distance[t];
}


void solve()
{
    cin>>n>>m>>s>>t>>u>>v;
    FOR(i,0,m){
        ll a,b,c;cin>>a>>b>>c;
        paths[a].pb({b,c});
        paths[b].pb({a,c});
    }

    dijisktra(s,t);

    ll strt = t;
    while(strt != s){
        // cout << strt << " ";
        int a = strt,b = connector[strt];
        strt = connector[strt];
        paths[a].pb({b,0});
        paths[b].pb({a,0});
    }
    // cout << s << endl;

    // cout << ans << endl;
    ans = 0;

    dijisktra(u,v);

    // strt = v;
    // while(strt != u){
    //     cout << strt << " ";
    //     strt = connector[strt];
    // }
    // cout << u << endl;

    cout << ans << endl;
}


int main()
{
    fastIO();
    // init();
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}

Compilation message (stderr)

commuter_pass.cpp: In function 'void init()':
commuter_pass.cpp:43:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     freopen("input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:44:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |     freopen("output.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...