Submission #1050075

#TimeUsernameProblemLanguageResultExecution timeMemory
1050075vjudge1Commuter Pass (JOI18_commuter_pass)C++17
0 / 100
158 ms23660 KiB
#include<bits/stdc++.h> #define en "\n" #define s second #define f first #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define vi vector<int> #define vii vector<pair<int,int>> #define int long long #define rall(x) x.rbegin(), x.rend() #define pb push_back #define loop(a) for(int i = 0; i < a; i++) #define loopv(i,a) for (int i = 0; i < a; i++) #define all(x) (x).begin(), (x).end() #define prDouble(x) printf("%.8f", x) #define goog(tno) printf("Case #%d: ", tno) using namespace std; const int INF = INT_MAX; typedef pair<int, int> pii; vi dijkstra(int start, int n, vector<vector<pii>>& adj) { vi dist(n, INF); priority_queue<pii, vector<pii>, greater<pii>> pq; dist[start] = 0; pq.push({0, start}); while (!pq.empty()) { int u = pq.top().second; int d = pq.top().first; pq.pop(); if (d > dist[u]) continue; for (auto& edge : adj[u]) { int v = edge.first; int cost = edge.second; if (dist[u] + cost < dist[v]) { dist[v] = dist[u] + cost; pq.push({dist[v], v}); } } } return dist; } signed main() { int N, M, S, T, U, V; cin>>N>>M>>S>>T>>U>>V; S--; T--; U--; V--; vector<vector<pii>> adj(N); vector<pair<pii, int>> edges; for (int i = 0; i < M; i++) { int A, B, C; cin >> A >> B >> C; A--; B--; adj[A].push_back({B, C}); adj[B].push_back({A, C}); edges.push_back({{A, B}, C}); } vector<int> distS = dijkstra(S, N, adj); int min_cost = INF; vector<int> distU = dijkstra(U, N, adj); for (auto& edge : edges) { int A = edge.first.first; int B = edge.first.second; int C = edge.second; if (distS[A] + C + distS[B] == distS[T] || distS[B] + C + distS[A] == distS[T]) { min_cost = min(min_cost, distU[V]); } else { min_cost = min(min_cost, distU[A] + distU[B] + C); } } cout<<min_cost<<en; 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...