Submission #875501

#TimeUsernameProblemLanguageResultExecution timeMemory
875501MinaRagy06Commuter Pass (JOI18_commuter_pass)C++17
0 / 100
152 ms262144 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int n, m, s, t, u, v;
	cin >> n >> m >> s >> t >> u >> v, s--, t--, u--, v--;
	ll adj[n][n];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			adj[i][j] = 1e18;
		}
	}
	for (int i = 0; i < n; i++) {
		adj[i][i] = 0;
	}
	while (m--) {
		int x, y, w;
		cin >> x >> y >> w;
		x--, y--;
		adj[x][y] = adj[y][x] = w;
	}
	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]);
			}
		}
	}
	ll ans = 1e18;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (adj[s][t] == adj[s][i] + adj[i][j] + adj[j][t]) {
				ans = min({ans, adj[u][i] + adj[j][v], adj[v][i] + adj[j][u]});
			}
		}
	}
	cout << ans << '\n';
	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...