Submission #683442

#TimeUsernameProblemLanguageResultExecution timeMemory
683442yogesh_saneCommuter Pass (JOI18_commuter_pass)C++17
0 / 100
2079 ms17272 KiB
#include <iostream> #include <vector> #include <queue> #include <stack> #include <climits> using namespace std; int n, m, s, t, u, v; vector<vector<pair<int, int>>>adj; void dijkstras(int start, int end, vector<long long> &dist, vector<bool> &path){ priority_queue<pair<long long, int>> q; vector<bool> visited(n+1); vector<vector<int>>parents(n+1); dist[start] = 0; q.push({0,start}); while(!q.empty()){ int node = q.top().second; q.pop(); if(visited[node]) continue; visited[node] = true; for(auto edge : adj[node]){ int next = edge.first; int weight = edge.second; if(dist[node] + weight < dist[next]){ dist[next] = dist[node] + weight; parents[next].clear(); parents[next].push_back(node); q.push({-dist[next],next}); }else if(dist[node] + weight == dist[next]){ parents[next].push_back(node); } } } stack<int>stk; stk.push(end); while(!stk.empty()){ int node = stk.top(); stk.pop(); path[node] = true; for(auto p : parents[node]) stk.push(p); } } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> s >> t >> u >> v; adj = vector<vector<pair<int, int>>>(n+1); for(int i = 0; i < m; i++){ int a, b, c; cin >> a >> b >> c; adj[a].push_back({b,c}); adj[b].push_back({a,c}); } vector<long long> distS(n+1, LONG_LONG_MAX), distV(n+1, LONG_LONG_MAX); vector<bool> pathS(n+1), pathV(n+1); dijkstras(s,t,distS,pathS); dijkstras(v,u,distV,pathV); long long ans = distV[u]; for(int i = 1; i <= n; i++){ if(pathS[i]) ans = min(ans, distV[i]); } cout << ans << '\n'; 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...