Submission #924096

#TimeUsernameProblemLanguageResultExecution timeMemory
924096MinaRagy06Commuter Pass (JOI18_commuter_pass)C++17
24 / 100
128 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; cin >> n >> m; int s, t, u, v; cin >> s >> t; cin >> u >> v; s--, t--, u--, v--; ll dist[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { dist[i][j] = 1e18; } dist[i][i] = 0; } for (int i = 0, x, y, w; i < m; i++) { cin >> x >> y >> w; x--, y--; dist[x][y] = dist[y][x] = w; } for (int k = 0; k < n; k++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); } } } ll mn = 1e18, best = 1e18; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (dist[s][i] + dist[i][j] + dist[j][t] < mn) { mn = dist[s][i] + dist[i][j] + dist[j][t]; best = min({dist[u][i] + dist[j][v], dist[v][i] + dist[j][u]}); } else if (dist[s][i] + dist[i][j] + dist[j][t] == mn) { best = min({best, dist[u][i] + dist[j][v], dist[v][i] + dist[j][u]}); } } } best = min(best, dist[u][v]); cout << best << '\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...