Submission #1140884

#TimeUsernameProblemLanguageResultExecution timeMemory
1140884buzdiCommuter Pass (JOI18_commuter_pass)C++17
16 / 100
309 ms40644 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; int type; bool operator < (const PQElement &other) const { return other.d < d; } }; struct Edge { int next_node, d, type; Edge(int next_node, int d, int type) : next_node(next_node), d(d), type(type) {} }; int n, m, s, t, x, y; vector<pair<int, int>> g[NMAX + 1]; vector<Edge> g1[NMAX + 1]; ll d[3][NMAX + 1]; void Dijkstra(int start, int which_start) { for(int i = 1; i <= n; i++) { d[which_start][i] = INF; } priority_queue<PQElement> pq; pq.push({start, 0, 0}); while(!pq.empty()) { auto [node, curent_d, type] = pq.top(); pq.pop(); if(d[which_start][node] == INF) { d[which_start][node] = curent_d; for(auto [next_node, edge_d] : g[node]) { pq.push({next_node, curent_d + edge_d, 0}); } } } } void CreateNewGraph() { for(int i = 1; i <= n; i++) { for(auto [j, edge_d] : g[i]) { if(d[0][i] + edge_d + d[1][j] == d[0][t]) { g1[i].emplace_back(j, 0, 1); g1[j].emplace_back(i, 0, 2); } else { g1[i].emplace_back(j, edge_d, 0); } } } } void Dijkstra1() { for(int i = 1; i <= n; i++) { d[0][i] = d[1][i] = d[2][i] = INF; } priority_queue<PQElement> pq; pq.push({x, 0, 0}); while(!pq.empty()) { auto [node, curent_d, type] = pq.top(); pq.pop(); if(d[type][node] == INF) { d[type][node] = curent_d; for(auto [next_node, edge_d, edge_type] : g1[node]) { if(edge_type == 0 || type == edge_type || x == node) { pq.push({next_node, curent_d + edge_d, edge_type}); } } } } } 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[a].emplace_back(b, c); g[b].emplace_back(a, c); } Dijkstra(s, 0); Dijkstra(t, 1); CreateNewGraph(); // cout << '\n'; // for(int i = 1; i <= n; i++) { // for(auto [j, edge_d, edge_type] : g1[i]) { // cout << i << ' ' << j << ' ' << edge_d << ' ' << edge_type << '\n'; // } // } Dijkstra1(); cout << min({d[0][y], d[1][y], d[2][y]}) << '\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...