Submission #1140902

#TimeUsernameProblemLanguageResultExecution timeMemory
1140902buzdiCommuter Pass (JOI18_commuter_pass)C++17
16 / 100
313 ms32832 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define ld long double using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const int NMAX = 1e5; const ll INF = 1e18; struct PQElement { int node; ll d; bool operator < (const PQElement &other) const { return other.d < d; } }; int n, m, s, t, x, y; vector<pair<int, int>> g[2][NMAX + 1]; ll d[4][NMAX + 1]; void Dijkstra(int start, int which_start, int which_graph) { for(int i = 1; i <= n; i++) { d[which_start][i] = INF; } priority_queue<PQElement> pq; pq.push({start, 0}); while(!pq.empty()) { auto [node, curent_d] = pq.top(); pq.pop(); if(d[which_start][node] == INF) { d[which_start][node] = curent_d; for(auto [next_node, edge_d] : g[which_graph][node]) { pq.push({next_node, curent_d + edge_d}); } } } } void CreateNewGraph(int type) { for(int i = 1; i <= n; i++) { g[1][i].clear(); } for(int i = 1; i <= n; i++) { for(auto [j, edge_d] : g[0][i]) { if(d[0][i] + edge_d + d[1][j] == d[0][t]) { if(type == 0) { g[1][i].emplace_back(j, 0); } else { g[1][j].emplace_back(i, 0); } } g[1][i].emplace_back(j, edge_d); } } } void Print() { cout << '\n'; for(int i = 1; i <= n; i++) { for(auto [j, edge_d] : g[1][i]) { cout << i << ' ' << j << ' ' << edge_d << '\n'; } } } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> s >> t >> x >> y; for(int i = 1; i <= m; i++) { int a, b, c; cin >> a >> b >> c; g[0][a].emplace_back(b, c); g[0][b].emplace_back(a, c); } Dijkstra(s, 0, 0); Dijkstra(t, 1, 0); CreateNewGraph(0); // Print(); Dijkstra(x, 2, 1); CreateNewGraph(1); // Print(); Dijkstra(y, 3, 1); // cout << d[3][y] << ' ' << d[4][y] << '\n'; cout << min(d[2][y], d[3][x]) << '\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...