Submission #1026807

#TimeUsernameProblemLanguageResultExecution timeMemory
1026807vjudge1Commuter Pass (JOI18_commuter_pass)C++17
15 / 100
484 ms40952 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int n, m; vector<int> G[100005]; map<pair<int,int>, int> dolz; void dijkstra1(int poc, int kraj) { int dist[n+1]; for (int i=1;i<=n;i++) dist[i]=10000000000000; dist[poc]=0; bool vis[n+1]={0}; priority_queue<pair<int,int> > pq; pq.push({0, poc}); int preth[n+1]; while (!pq.empty()) { int teme=pq.top().second; pq.pop(); if (vis[teme]) continue; vis[teme]=1; if (teme==kraj) break; for (auto next:G[teme]) { int dist_between=dolz[{teme,next}]; if (dist[teme]+dist_between<dist[next]) { dist[next]=dist[teme]+dist_between; preth[next]=teme; pq.push({-dist[next], next}); } } } int teme=kraj; while (teme!=poc) { dolz[{teme, preth[teme]}]=0; dolz[{preth[teme], teme}]=0; teme=preth[teme]; } } int dijkstra2(int poc, int kraj) { int dist[n+1]; for (int i=1;i<=n;i++) dist[i]=10000000000000; dist[poc]=0; bool vis[n+1]={0}; priority_queue<pair<int,int> > pq; pq.push({0, poc}); while (!pq.empty()) { int teme=pq.top().second; pq.pop(); if (vis[teme]) continue; vis[teme]=1; if (teme==kraj) return dist[teme]; for (auto next:G[teme]) { int dist_between=dolz[{teme,next}]; if (dist[teme]+dist_between<dist[next]) { dist[next]=dist[teme]+dist_between; pq.push({-dist[next], next}); } } } return 0; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); int 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); G[b].push_back(a); dolz[{a,b}]=c; dolz[{b,a}]=c; } dijkstra1(s, t); cout << dijkstra2(u, v); 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...