Submission #685337

#TimeUsernameProblemLanguageResultExecution timeMemory
685337saayan007Commuter Pass (JOI18_commuter_pass)C++17
16 / 100
210 ms19856 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pi = pair<int, int>; using pl = pair<long long, long long>; using vi = vector<int>; using vl = vector<long long>; using vpi = vector<pair<int, int>>; using vpl = vector<pair<long long, long long>>; #define fur(i, a, b) for(ll i = a; i <= (ll)b; ++i) #define ruf(i, a, b) for(ll i = a; i >= (ll)b; --i) #define fr first #define sc second #define mp make_pair #define pb emplace_back #define nl "\n" #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() const ll mxn = 1e5L + 1; const ll inf = 1e16L; ll n, m, s, t, u, v; vpl adj[mxn]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m >> s >> t >> u >> v; fur(i, 1, m) { ll a, b, c; cin >> a >> b >> c; adj[a].pb(b, c); adj[b].pb(a, c); } priority_queue<pl> pq; ll dist[n + 1]; fur(i, 1, n) { dist[i] = inf; } dist[s] = 0; pq.emplace(-dist[s], s); while(!pq.empty()) { ll a = pq.top().sc; if(dist[a] + pq.top().fr != 0) { pq.pop(); continue; } pq.pop(); for(auto [b, c] : adj[a]) { if(dist[b] > dist[a] + c) { dist[b] = dist[a] + c; pq.emplace(-dist[b], b); } } } bool zer[n + 1] = {}; pq.emplace(dist[t], t); while(!pq.empty()) { ll a = pq.top().sc; pq.pop(); if(zer[a]) continue; zer[a] = 1; for(auto [b, c] : adj[a]) { if(dist[a] - c == dist[b]) { pq.emplace(dist[b], b); } } } ll ans = inf; fur(i, 1, n) dist[i] = inf; dist[v] = 0; pq.emplace(-dist[v], v); while(!pq.empty()) { ll a = pq.top().sc; // cout << a << ' ' << dist[a] << nl;; if(dist[a] + pq.top().fr != 0) { pq.pop(); continue; } pq.pop(); if(zer[a]) { ans = min(ans, dist[a]); } for(auto [b, c] : adj[a]) { if(zer[a] && zer[b]) c = 0; if(dist[b] > dist[a] + c) { dist[b] = dist[a] + c; pq.emplace(-dist[b], b); } } } // cout <<nl; // fur(i, 1, n) { // cout << dist[i] << ' '; // } // cout << nl; cout << ans << nl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...