Submission #1274042

#TimeUsernameProblemLanguageResultExecution timeMemory
1274042crispxxCommuter Pass (JOI18_commuter_pass)C++20
0 / 100
158 ms327680 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define all(x) x.begin(), x.end() #define pb push_back #define ar array #define nl '\n' template <typename A, typename B> bool chmin(A &a, const B &b) { if(a > b) { return a = b, true; } return false; } template <typename A, typename B> bool chmax(A &a, const B &b) { if(a < b) { return a = b, true; } return false; } const int inf = 1e18; void solve() { int n, m; cin >> n >> m; int S, T, U, V; cin >> S >> T >> U >> V; S--, T--, U--, V--; // vector<vector<ar<int, 2>>> adj(n); vector<vector<int>> d(n, vector<int>(n, inf)); for(int i = 0; i < n; i++) d[i][i] = 0; for(int i = 0; i < m; i++) { int u, v, w; cin >> u >> v >> w; u--, v--; // adj[u].pb({v, w}); // adj[v].pb({u, w}); chmin(d[u][v], w); chmin(d[v][u], w); } for(int k = 0; k < n; k++) { for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { if(d[i][k] < inf && d[k][j] < inf) { chmin(d[i][j], d[i][k] + d[k][j]); } } } } int ans = d[U][V]; // cout << d[S][T] << nl; // cout << d[U][V] << nl; for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { if(d[S][i] + d[i][j] + d[j][T] == d[S][T] ) { chmin(ans, d[U][i] + d[j][V]); chmin(ans, d[U][j] + d[i][V]); // cout << i + 1 << ' ' << j + 1 << ' ' << d[U][i] + d[j][V] << nl; } } } cout << ans << nl; // vector<ar<int, 4>> d(n, {inf, inf, inf, inf}); // vector<int> p(n); // auto D = [&](int s, int j) -> void { // d[s][j] = 0; // p[s] = -1; // priority_queue<ar<int, 2>, vector<ar<int, 2>>, greater<>> pq; // pq.push({0, s}); // while(!pq.empty()) { // auto [d_v, v] = pq.top(); // pq.pop(); // if(d_v != d[v][j]) continue; // for(auto [to, w] : adj[v]) { // if( chmin(d[to][j], d_v + w) ) { // pq.push({d[to][j], to}); // p[to] = v; // } // } // } // }; // D(U, 0), D(V, 1), D(S, 2); // vector<int> path; // for(auto v = T; v != -1; v = p[v]) { // path.pb(v); // } // int ans1 = inf, ans2 = inf; // for(auto &x : path) { // chmin(ans1, d[x][0]); // chmin(ans2, d[x][1]); // } // int ans = d[V][0]; // chmin(ans, ans1 + ans2); // cout << ans << nl; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...