/*
In the name of Allah
made by: Ahmed_Solyman
*/
#include <bits/stdc++.h>
#include <ext/rope>
using namespace std;
using namespace __gnu_cxx;
#pragma GCC optimize("-Ofast")
#pragma GCC optimize("-O1")
//-------------------------------------------------------------//
typedef long long ll;
typedef unsigned long long ull;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI acos(-1)
#define lb lower_bound
#define ub upper_bound
#define endl '\n'
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define sum_to(n) (n*(n+1))/2
#define pb push_back
#define pf push_front
#define fil(arr,x) memset(arr,x,sizeof(arr))
#define REP(i,a,b) for (int i=a;i<=b;i++)
#define F first
#define S second
#define MP make_pair
const ll mod=1e9+7;
int dx[8]={0,1,0,-1,1,1,-1,-1};
int dy[8]={1,0,-1,0,1,-1,-1,1};
//-------------------------------------------------------------//
ll lcm(ll a,ll b)
{
return (max(a,b)/__gcd(a,b))*min(a,b);
}
void person_bool(bool x)
{
cout<<(x?"YES":"NO")<<endl;
}
const int N=305+5;
int n,m,s,t,u,v;
vector<vector<ll>>dist(N,vector<ll>(N,1e18));
vector<pair<int,int>>adj[N];
int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
fast
cin>>n>>m>>s>>t>>u>>v;
cout<<dist[1][1]<<endl;
for(int i=0;i<m;i++){
int a,b,c;
cin>>a>>b>>c;
adj[a].push_back({b,c});
adj[b].push_back({a,c});
dist[a][b]=dist[b][a]=min(dist[a][b],c*1LL);
}
for(int i=1;i<=n;i++)dist[i][i]=0;
for(int k=1;k<=n;k++){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
dist[i][j]=dist[j][i]=min(dist[i][j],dist[i][k]+dist[k][j]);
}
}
}
ll ans=dist[u][v];
for(int x=1;x<=n;x++){
for(int y=1;y<=n;y++){
if(x!=y){
if(dist[s][x] + dist[x][y] + dist[y][t] == dist[s][t]){
ans=min(ans,dist[u][x] + dist[y][v]);
ans=min(ans,dist[u][y] + dist[x][v]);
}
}
}
}
cout<<ans<<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... |