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"
#define ll long long
using namespace std;
int n, m, s, t, u, v;
int a[100005];
ll dist[100005], distt[305][305];
vector<pair<int, ll>> node[100005];
int ind;
ll ans;
void dfs(int x) {
a[ind++] = x;
if(x == t) {
ll p1 = 1e18, p2 = 1e18;
for(int i = 0; i < ind; i++) {
p1 = min(p1, distt[u][a[i]]);
p2 = min(p2, distt[v][a[i]]);
}
ans = min(ans, p1 + p2);
ind--;
return;
}
for(auto [y, d] : node[x]) {
if(dist[x] + d <= dist[y]) {
dist[y] = dist[x] + d;
dfs(y);
}
}
ind--;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m >> s >> t >> u >> v;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++)
distt[i][j] = 1e18;
distt[i][i] = 0;
}
for(int i = 0; i < m; i++) {
int a, b;
ll c;
cin >> a >> b >> c;
node[a].push_back({b, c});
node[b].push_back({a, c});
distt[a][b] = distt[b][a] = c;
}
for(int k = 1; k <= n; k++) {
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
if(distt[i][k] + distt[k][j] < distt[i][j])
distt[i][j] = distt[i][k] + distt[k][j];
}
}
}
for(int i = 1; i <= n; i++)
dist[i] = distt[s][i];
ans = distt[u][v];
dfs(s);
cout << ans;
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... |