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;
#define int long long
typedef pair<int, int> pii;
const int MXN = 100005;
int n, m, s, t, u, v, father[MXN], du[MXN], dv[MXN], uu = LLONG_MAX, vv = LLONG_MAX;
vector<pii> edge[MXN];
vector<int> path;
bitset<MXN> b;
void GET_PATH() {
b.reset();
priority_queue<pair<int, pii>, vector<pair<int, pii>>, greater<pair<int, pii>>> pq;
pq.push({0, {0, s}});
while (pq.size()) {
pair<int, pii> now = pq.top();
pq.pop();
if (b[now.second.second]) continue;
b[now.second.second] = true;
father[now.second.second] = now.second.first;
for (auto &i : edge[now.second.second]) {
if (b[i.first]) continue;
pq.push({now.first + i.second, {now.second.second, i.first}});
}
}
int now = t;
path.push_back(now);
while (now != s) {
now = father[now];
path.push_back(now);
}
}
void DIJKSTRA(int start, int *arr) {
b.reset();
priority_queue<pii, vector<pii>, greater<pii>> pq;
pq.push({0, start});
while (pq.size()) {
pii now = pq.top();
pq.pop();
if (b[now.second]) continue;
b[now.second] = true;
arr[now.second] = now.first;
for (auto &i : edge[now.second]) {
if (b[i.first]) continue;
pq.push({now.first + i.second, i.first});
}
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int x, y, z;
cin >> n >> m >> s >> t >> u >> v;
for (int i = 0; i < m; i++) {
cin >> x >> y >> z;
edge[x].push_back({y, z});
edge[y].push_back({x, z});
}
GET_PATH();
DIJKSTRA(u, du);
DIJKSTRA(v, dv);
for (auto &i : path) {
uu = min(uu, du[i]);
vv = min(vv, dv[i]);
}
cout << min(du[v], uu + vv) << endl;
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... |