Submission #1053719

#TimeUsernameProblemLanguageResultExecution timeMemory
1053719tht2005Commuter Pass (JOI18_commuter_pass)C++17
24 / 100
27 ms1884 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 303; int n, m, s, t, u, v; long long d[MAXN][MAXN]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m >> s >> t >> u >> v; memset(d, 0x3f, sizeof(d)); for(int i = 1; i <= n; ++i) d[i][i] = 0; while(m--) { int a, b; long long c; cin >> a >> b >> c; d[a][b] = min(d[a][b], c); d[b][a] = min(d[b][a], c); } for(int k = 1; k <= n; ++k) for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) d[i][j] = min(d[i][j], d[i][k] + d[k][j]); long long ans = d[u][v]; for(int i = 1; i <= n; ++i) { if(d[s][i] + d[i][t] != d[s][t]) continue; for(int j = 1; j <= n; ++j) { if(d[s][i] + d[i][j] + d[j][t] != d[s][t]) continue; ans = min(ans, d[u][i] + d[j][v]); ans = min(ans, d[u][j] + d[i][v]); } } cout << ans; 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...