Submission #532740

#TimeUsernameProblemLanguageResultExecution timeMemory
532740nafis_shifatEscape Route (JOI21_escape_route)C++17
5 / 100
9062 ms161928 KiB
#include "escape_route.h" #include<bits/stdc++.h> #define ll long long #define pii pair<ll, ll> const ll inf = 1e18; const int mxn = 3e5 + 5; using namespace std; vector<int> adj[mxn]; int n, m; ll s, q; int l[mxn], r[mxn]; ll c[mxn], w[mxn]; ll dijkstra(int source, int target, ll t) { priority_queue <tuple<ll, ll, int>, vector<tuple<ll, ll, int>>, greater<tuple<ll, ll, int>> > pq; pq.push({0, t, source}); int vis[n + 1][2] = {}; pii dist[n + 1]; for(int i = 0; i < n; i++) dist[i] = {inf, inf}; dist[source] = {0, t}; while(!pq.empty()) { auto [d, T, u] = pq.top(); pq.pop(); if(T > 0 && vis[u][1]) continue; if(T == 0 && vis[u][0]) continue; if(T == 0) vis[u][0] = 1; else vis[u][1] = 1; pq.push({d + 1, 0, u}); for(int i : adj[u]) { int v = l[i] ^ r[i] ^ u; if(T + w[i] <= c[i]) { if(dist[v] > make_pair(d, T + w[i])) { dist[v] = make_pair(d, T + w[i]); pq.push({d, T + w[i], v}); } } } } ll res = s * dist[target].first + dist[target].second; return res - t; } vector<ll> calculate_necessary_time( int N, int M, ll S, int Q, vector<int> A, vector<int> B, vector<ll> L, vector<ll> C, vector<int> U, vector<int> V, vector<ll> T) { n = N; m = M; s = S; q = Q; for(int i = 0; i < M; i++) { adj[A[i]].push_back(i); adj[B[i]].push_back(i); l[i] = A[i]; r[i] = B[i]; c[i] = C[i]; w[i] = L[i]; } vector<ll> res(Q); for(int i = 0; i < Q; i++) { res[i] = dijkstra(U[i], V[i], T[i]); } return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...