#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int NMAX = 1e5;
const ll INF = 1e18;
struct PQElement {
int node;
ll d;
bool operator < (const PQElement &other) const {
return other.d < d;
}
};
int n, m, s, t, x, y;
vector<pair<int, int>> g[2][NMAX + 1];
ll d[2][NMAX + 1];
void Dijkstra(int start, int which_start, int which_graph) {
for(int i = 1; i <= n; i++) {
d[which_start][i] = INF;
}
priority_queue<PQElement> pq;
pq.push({start, 0});
while(!pq.empty()) {
auto [node, curent_d] = pq.top();
pq.pop();
if(d[which_start][node] == INF) {
d[which_start][node] = curent_d;
for(auto [next_node, edge_d] : g[which_graph][node]) {
pq.push({next_node, curent_d + edge_d});
}
}
}
}
void CreateNewGraph() {
for(int i = 1; i <= n; i++) {
for(auto [j, edge_d] : g[0][i]) {
if(d[0][i] + edge_d + d[1][j] == d[0][t]) {
g[1][i].emplace_back(j, 0);
g[1][j].emplace_back(i, 0);
}
else {
g[1][i].emplace_back(j, edge_d);
}
}
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> s >> t >> x >> y;
for(int i = 1; i <= m; i++) {
int a, b, c;
cin >> a >> b >> c;
g[0][a].emplace_back(b, c);
g[0][b].emplace_back(a, c);
}
Dijkstra(s, 0, 0);
Dijkstra(t, 1, 0);
CreateNewGraph();
// cout << '\n';
// for(int i = 1; i <= n; i++) {
// for(auto [j, edge_d] : g[1][i]) {
// cout << i << ' ' << j << ' ' << edge_d << '\n';
// }
// }
Dijkstra(x, 0, 1);
cout << d[0][y] << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |