# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
547556 | tmn2005 | 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<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define int long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define all(s) s.begin(), s.end()
#define allr(s) s.rbegin(), s.rend()
#define NeedForSpeed ios::sync_with_stdio(0), cin.tie(0)
#define ordered_set tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
const int N = 1e5 + 12, INF = 1e18;
int n, m, k, a, b, c, d, s, f, l, r, x, y, z, res = INF, dis[505][505];
//vector<pii> g[N];
//vector<int> ds(N, INF), df(N, INF), dl(N, INF), dr(N, INF);
void solve(){
cin>>n>>m;
cin>>s>>f;
cin>>l>>r;
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
if(i == j)
dp[i][j] = 0;
else
dp[i][j] = INF;
}
}
for(int i=1; i<=m; i++){
cin>>x>>y>>z;
dis[x][y] = z;
dis[y][x] = z;
}
for(int i=1; i<=n; i++)dis[i][i] = 0;
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
for(int k=1; k<=n; k++){
dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
}
}
}
res = dis[l][r];
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
if(dis[s][i] + dis[i][j] + dis[j][f] == dis[s][f]){
res = min(res, dis[l][i] + dis[j][r]);
res = min(res, dis[r][i] + dis[j][l]);
}
}
}
cout<<res<<"\n";
}
main(){
NeedForSpeed;
int T = 1;
// cin >> T;
while(T--){
solve();
}
return 0;
}