제출 #961193

#제출 시각아이디문제언어결과실행 시간메모리
961193LCJLYCommuter Pass (JOI18_commuter_pass)C++14
24 / 100
149 ms262144 KiB
#include <bits/stdc++.h>
using namespace std;	
 
#define int long long 
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << "  " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << "  " << j << " " << #i << "  " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<long long,int>pii;
//typedef pair<pii,pii>pi2;
typedef array<int,6>pi2;

void solve(){
	int n,m;
	cin >> n >> m;
	int a,b;
	cin >> a >> b;
	int s,t;
	cin >> s >> t;
	
	int adj[n+5][n+5];
	memset(adj,-1,sizeof(adj));
	int temp,temp2,temp3;
	for(int x=1;x<=n;x++) adj[x][x]=0;
	for(int x=0;x<m;x++){
		cin >> temp >> temp2 >> temp3;
		if(adj[temp][temp2]==-1||(temp3<adj[temp][temp2])){
			adj[temp][temp2]=temp3;
			adj[temp2][temp]=temp3;
		}
	}
	
	for(int k=1;k<=n;k++){
		for(int x=1;x<=n;x++){
			for(int y=1;y<=n;y++){
				if(adj[x][k]==-1||adj[k][y]==-1) continue;
				if(adj[x][y]!=-1&&adj[x][y]<=adj[x][k]+adj[k][y]) continue;
				adj[x][y]=adj[x][k]+adj[k][y];
			}
		}
	}
	
	int target=adj[a][b];
	int best=adj[s][t];
	
	for(int x=1;x<=n;x++){
		for(int y=1;y<=n;y++){
			int mini=min(adj[a][x]+adj[b][y],adj[a][y]+adj[b][x])+adj[x][y];
			if(mini==target){
				best=min({best,adj[x][s]+adj[y][t],adj[x][t]+adj[y][s]});
			}
		}
	}
	
	cout << best;
}
 
int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin >> t;
	while(t--){
		solve();
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...