From a96b65cbfad7f62f3db6b2eab105e4e25c0414c5 Mon Sep 17 00:00:00 2001 From: Jack Sangdahl Date: Fri, 27 Jun 2025 12:23:02 -0600 Subject: chore: remove old cpp and rust solutions --- other/path_max_probability.cpp | 52 ------------------------------------------ 1 file changed, 52 deletions(-) delete mode 100644 other/path_max_probability.cpp (limited to 'other/path_max_probability.cpp') diff --git a/other/path_max_probability.cpp b/other/path_max_probability.cpp deleted file mode 100644 index 467829e..0000000 --- a/other/path_max_probability.cpp +++ /dev/null @@ -1,52 +0,0 @@ -// 1514. Path with Maximum Probability -#include "leetcode.h" - -/* - * given an undirected weighted graph of 'n' nodes (0-indexed). represented by - * an edge list where 'edges[i] = [a, b]' is an undirected edge connecting the - * nodes 'a' and 'b' with a probability of success of traversing that edge - * 'succ_prob[i]'. given two nodes 'start, end', find the path with the maximum - * probability of success to go from 'start' to 'end' and return its success - * probability. if there is no path from 'start' to 'end', return 0. your answer - * will be accepted if it differs from the correct answer by at most '1e-5' - */ - -class Solution { -public: - double maxProbability(int n, vvd & edges, vector &succ_prob, - int start, int end) { - vector>> vvp(n); - for (int i = 0; i < edges.size(); i++) { - vvp[edges[i][0]].push_back({edges[i][1], succ_prob[i]}); - vvp[edges[i][1]].push_back({edges[i][0], succ_prob[i]}); - } - vector seen(n, 0); - priority_queue> pqp; - pqp.push({(double)1.0, start}); - vector mx(n, (double)0.0); - mx[start] = 1.0; - while (!pqp.empty()) { - auto top = pqp.top(); - pqp.pop(); - double prob_a = top.first; - int node = top.second; - if (!seen[node]) { - seen[node]++; - for (auto to : vvp[node]) - if (mx[to.first] < to.second * prob_a) { - mx[to.first] = to.second * prob_a; - pqp.push({mx[to.first], to.first}); - } - } - } - return mx[end]; - } -}; - -int main() { - Solution obj; - vvd e1 = {{0, 1}, {1, 2}, {0, 2}}, e2 = {{0, 1}, {1, 2}, {0, 2}}; - vector sp1 = {0.5, 0.5, 0.2}, sp2 = {0.5, 0.5, 0.3}; - printf("%f\n", obj.maxProbability(3, e1, sp1, 0, 2)); // expect: 0.25000 - printf("%f\n", obj.maxProbability(3, e2, sp2, 0, 2)); // expect: 0.30000 -} -- cgit v1.2.3