# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
884444 | DAleksa | Commuter Pass (JOI18_commuter_pass) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
struct node {
int v;
int w;
};
const int N = 1e5 + 10;
int n, m;
int S, T, U, V;
vector<node> g[N];
vector<long long> distS(N), distT(N), distU(N), distV(N);
int fst[N];
long long dp[N];
void dijkstra(int start, vector<long long>& dist) {
for(int i = 1; i <= n; i++) dist[i] = 1e18;
dist[start] = 0;
set<pair<long long, int>> s;
s.insert({0, start});
while(!s.empty()) {
pair<long long, int> p = *s.begin();
s.erase(s.begin());
long long d = p.first;
int u = p.second;
for(node v : g[u]) {
if(dist[u] + v.w < dist[v.v]) {
dist[v.v] = dist[u] + v.w;
s.insert({dist[v.v], v.v});
}
}
}
}
void find_dp(int u) {
if(dp[u] != -1) return;
dp[u] = 1e18;
if(distS[u] + distT[u] != distS[T]) return;
for(int v : g[u]) {
if()
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> S >> T >> U >> V;
for(int i = 0; i < m; i++) {
int u, v, w;
cin >> u >> v >> w;
g[u].push_back({v, w});
g[v].push_back({u, w});
}
dijkstra(S, distS);
dijkstra(T, distT);
dijkstra(U, distU);
dijkstra(V, distV);
for(int i = 1; i <= n; i++) {
fst[i] = i;
dp[i] = -1;
}
long long ans = 1e18;
for(int i = 1; i <= n; i++) {
if(dp[i] == -1) find_dp(i);
ans = min(ans, dp[i]);
}
// for(int i = 1; i <= n; i++) cout << dp[i] << " ";
// cout << "\n";
cout << ans;
return 0;
}