category-wise-problems

contains category wise problems(data structures, competitive) of popular platforms.

View the Project on GitHub mayankdutta/category-wise-problems

Flight discount, Medium, modified Djikstra

Approach

Code sample ```cpp #define Graph vector<vector<pair<long long int, long long int>>> Graph graph, graphRev; vector dji(const ll &source, const Graph &graph) { ll n = graph.size(); vector dist(n + 1, 2e18); priority_queue<pll, vector, greater> pq; pq.push({0, source}); dist[source] = 0; while (!pq.empty()) { auto [d, u] = pq.top(); pq.pop(); if (dist[u] < d) continue; for (const auto &[v, dd] : graph[u]) { if (dd + dist[u] < dist[v]) { dist[v] = dd + dist[u]; pq.push({dist[v], v}); } } } return dist; } void solve() { ll n, m; cin >> n >> m; graph = graphRev = Graph(n + 1); vector<tuple<ll, ll, ll>> arr; for (int i = 0; i < m; i++) { ll a, b, w; cin >> a >> b >> w; graph[a].push_back({b, w}); graphRev[b].push_back({a, w}); arr.push_back({a, b, w}); } auto one = dji(1, graph); auto two = dji(n, graphRev); ll ans = ll(2e18); for (const auto &[from, to, w] : arr) { ans = min(ans, one[from] + two[to] + (w) / 2); } cout << ans << '\n'; } ``` </details>