Submission #963143

#TimeUsernameProblemLanguageResultExecution timeMemory
963143toast12Commuter Pass (JOI18_commuter_pass)C++14
24 / 100
162 ms262144 KiB
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; int main() { int n, m; cin >> n >> m; int s, t, u, v; cin >> s >> t >> u >> v; vector<vector<long long>> dist(n+1, vector<long long>(n+1, INF)); for (int i = 0; i < m; i++) { int x, y; long long w; cin >> x >> y >> w; dist[x][x] = 0; dist[y][y] = 0; dist[x][y] = w; dist[y][x] = w; } // Floyd-Warshall's // finding the shortest path from i to j by find the path from i to k and k to j for (int k = 1; k <= n; k++) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]); } } } long long ans = dist[u][v]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (dist[s][i]+dist[i][j]+dist[j][t] == dist[s][t]) { ans = min(ans, min({dist[u][i]+dist[v][i], dist[u][j]+dist[v][j], dist[u][i]+dist[v][j], dist[u][j]+dist[v][i]})); } } } 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...