Submission #854253

#TimeUsernameProblemLanguageResultExecution timeMemory
854253_callmelucianCommuter Pass (JOI18_commuter_pass)C++14
0 / 100
204 ms25240 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,int> pl; typedef tuple<int,int,int> tt; #define all(v) v.begin(), v.end() const int mn = 1e5 + 10; ll dist[4][mn], dp[mn]; vector<pl> adj[mn], subg[mn]; bool vis[mn]; int n, node; void dijkstra (int save, int source) { for (int i = 1; i <= n; i++) vis[i] = 0, dist[save][i] = LLONG_MAX; dist[save][source] = 0; priority_queue<pl> pq; pq.push({0, source}); while (pq.size()) { int a = pq.top().second; pq.pop(); if (vis[a]) continue; vis[a] = 1; for (pl it : adj[a]) { ll w; int b; tie(w, b) = it; if (dist[save][a] + w < dist[save][b]) { dist[save][b] = dist[save][a] + w; pq.push({-dist[save][b], b}); } } } return; } void addEdge (int a, int b, ll c, bool way = 1) { subg[a].push_back({c, b}); if (way) subg[b].push_back({c, a}); } ll finalD() { for (int i = 0; i <= node; i++) vis[i] = 0, dp[i] = LLONG_MAX; dp[0] = 0; priority_queue<pl> pq; pq.push({0, 0}); while (pq.size()) { int a = pq.top().second; pq.pop(); if (vis[a]) continue; vis[a] = 1; for (pl it : subg[a]) { ll w; int b; tie(w, b) = it; if (dp[a] + w < dp[b]) { dp[b] = dp[a] + w; pq.push({-dp[b], b}); } } } return dp[node]; } int main() { ios::sync_with_stdio(0); cin.tie(0); int m; cin >> n >> m; int s, t, u, v; cin >> s >> t >> u >> v; node = n + 1; vector<tt> edge(m); for (int i = 0; i < m; i++) { int a, b, c; cin >> a >> b >> c; adj[a].push_back({c, b}); adj[b].push_back({c, a}); edge[i] = make_tuple(a, b, c); } dijkstra(0, s); dijkstra(1, t); dijkstra(2, u); dijkstra(3, v); for (int i = 1; i <= n; i++) { if (dist[0][i] + dist[1][i] > dist[0][t]) continue; addEdge(0, i, dist[2][i]); addEdge(i, node, dist[3][i]); } for (int i = 0; i < m; i++) { int a, b; ll c; tie(a, b, c) = edge[i]; if (dist[0][a] + c + dist[1][b] == dist[0][t] && dist[0][a] + c == dist[0][b]) addEdge(a, b, 0, 0); if (dist[0][b] + c + dist[1][a] == dist[0][t] && dist[0][b] + c == dist[0][b]) addEdge(b, a, 0, 0); } cout << finalD(); 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...