Submission #833742

#TimeUsernameProblemLanguageResultExecution timeMemory
833742vjudge1Commuter Pass (JOI18_commuter_pass)C++17
0 / 100
106 ms262144 KiB
#include<bits/stdc++.h>
using namespace std;

// // PBDS Template
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//
//template <class T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
//using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;

// Preset
const int maxn = 200000;
const int INF = INT_MAX;
const long long int LINF = LLONG_MAX;
const long long int mod = 1e9 + 7;
const long long int mod2 = 998244353;
//const double e = 2.71828;
const double PI = acos(-1);
const double eps = 1e-10;
#define pb push_back
#define ll long long
#define ull unsigned long long
typedef pair<char,char> pc;
typedef pair<double,double> pd;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<pi,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<string,int> psi;
typedef pair<int,string> pis;
typedef pair<char,int> pci;
typedef pair<int,char> pic;
typedef pair<int,double> pid;
typedef pair<double,int> pdi;
int dr[4] = {0,1,0,-1}, dc[4] = {1,0,-1,0};

const ll lim = 1e15;

void solve() {
	ll n,m,s,t,u,v;
	cin >> n >> m >> s >> t >> u >> v;
	ll adj[n+5][n+5], fw[n+5][n+5];
	for (ll i=1; i<=n; i++) {
		for (ll j=1; j<=n; j++) {
			adj[i][j] = lim;
			fw[i][j] = lim;
		}
	}
	for (ll i=1; i<=m; i++) {
		ll a,b,c;
		cin >> a >> b >> c;
		adj[a][b] = c;
		adj[b][a] = c;
		fw[a][b] = c;
		fw[b][a] = c;
	}
	for (ll k=1; k<=n; k++) {
		for (ll i=1; i<=n; i++) {
			for (ll j=1; j<=n; j++) {
				if (fw[i][k] < lim && fw[k][j] < lim) {
					fw[i][j] = min(fw[i][j], fw[i][k] + fw[k][j]);
				}
			}
		}
	}
	ll new_adj[n+5][n+5], new_fw[n+5][n+5];
	for (ll i=1; i<=n; i++) {
		for (ll j=1; j<=n; j++) {
			if (adj[i][j] == lim) {
				new_adj[i][j] = lim;
				new_fw[i][j] = lim;
				continue;
			}
			if (fw[i][j] + fw[j][t] == fw[i][t]) new_adj[i][j] = 0ll;
			else new_adj[i][j] = adj[i][j];
			new_fw[i][j] = new_adj[i][j];
		}
	}
	for (ll k=1; k<=n; k++) {
		for (ll i=1; i<=n; i++) {
			for (ll j=1; j<=n; j++) {
				if (new_fw[i][k] < lim && new_fw[k][j] < lim) {
					new_fw[i][j] = min(new_fw[i][j], new_fw[i][k] + new_fw[k][j]);
				}
			}
		}
	}
	ll ans = new_fw[u][v];
	cout << ans << '\n';
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
//	precompute();
//	FFT::init_fft();
	int tc=1;
//	cin >> tc;
//	getchar();
//	int idx = 0;
	while (tc--) solve();
 	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...