Submission #1129874

#TimeUsernameProblemLanguageResultExecution timeMemory
1129874julia_08Commuter Pass (JOI18_commuter_pass)C++20
24 / 100
50 ms4524 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int MAXN = 310; const int INF = 1e18; vector<pair<int, int>> adj[MAXN]; int marc[MAXN][MAXN], dist[MAXN][MAXN]; int n, m; void dijkstra(int x){ for(int i=1; i<=n; i++){ dist[i][x] = INF; } priority_queue<pair<int, int>> q; dist[x][x] = 0; q.push({0, x}); while(!q.empty()){ auto [d, v] = q.top(); q.pop(); if(marc[v][x]) continue; marc[v][x] = 1; for(auto [u, w] : adj[v]){ if(dist[v][x] + w < dist[u][x]){ dist[u][x] = dist[v][x] + w; q.push({-dist[u][x], u}); } } } } int32_t main(){ cin.tie(0)->sync_with_stdio(0); cin >> n >> m; int s, t; cin >> s >> t; int u, v; cin >> u >> v; for(int i=1; i<=m; i++){ int a, b, c; cin >> a >> b >> c; adj[a].push_back({b, c}); adj[b].push_back({a, c}); } for(int i=1; i<=n; i++){ dijkstra(i); } int 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[j][v], dist[u][j] + dist[i][v])); } } } 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...