Submission #1162138

#TimeUsernameProblemLanguageResultExecution timeMemory
1162138AliyyiakbarCommuter Pass (JOI18_commuter_pass)C++20
15 / 100
214 ms24908 KiB
/* #ifndef ONLINE_JUDGE #include "AkbarKING.h" #else #define debug(...) #define debugArr(...) #define debugG(...) #endif */ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define int long long #define $AzH_TxdmN$ ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr); #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native") #pragma GCC optimize("Ofast") #pragma GCC optimize("no-stack-protector") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("fast-math") #define ep emplace_back #define pb push_back #define pii pair<int,int> #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define heap pii, vector<pii>, greater<pii> using namespace std; using namespace __gnu_pbds; template <typename T> using __indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template <typename T> using __indexed_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int sz = 3e5+9; const int LOG = 63; const int MOD = 1e9+7; const int INF = 1e18; vector<pii> v[sz]; int dp[2][sz]; int n, m; array<int, 2> start; array<int, 2> endd; int run = 0; set<int> freeEdges; void djk(int x) { ++run; priority_queue<pii, vector<pii>, greater<pii>> pq; for (int i = 0; i <= n; ++i) { dp[0][i] = INF; dp[1][i] = -1; } dp[0][x] = 0; pq.emplace(dp[0][x], x); while(!pq.empty()) { int w = pq.top().first; int node = pq.top().second; pq.pop(); if(w > dp[0][node]) continue; for (auto to : v[node]) { int neighbor = to.first; int costEdge = to.second; int additional = costEdge; if(run == 2) { long long key = (min(node, neighbor))*(n+1) + max(node, neighbor); if(freeEdges.count(key) > 0) { additional = 0; } } if (dp[0][neighbor] > dp[0][node] + additional) { dp[0][neighbor] = dp[0][node] + additional; dp[1][neighbor] = node; pq.emplace(dp[0][neighbor], neighbor); } } } if (run == 1) { int cur = endd[0]; while(cur != start[0] && cur != -1) { int prev = dp[1][cur]; if(prev == -1) break; int key = (min(cur, prev))*(n+1) + max(cur, prev); freeEdges.insert(key); cur = prev; } } } void solve() { cin >> n >> m >> start[0] >> endd[0] >> start[1] >> endd[1]; for (int i = 0, x, y, z; i < m; ++i) { cin >> x >> y >> z; v[x].ep(y, z); v[y].ep(x, z); } djk(start[0]); djk(start[1]); cout << dp[0][endd[1]] << '\n'; } signed main() { $AzH_TxdmN$ int t = 1; // cin >> t; while (t--) { 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...