11.dijksta 最短路径(最大概率)
class Solution { vector<vector<pair<int,double> > >v; public: double maxProbability(int n, vector<vector<int>>& edges, vector<double>& succProb, int start, int end) { v.resize(n); vector<double> dist(n,0.0); dist[start]=1.0; for(int i=0;i<edges.size();i++){ int a=edges[i][0],b=edges[i][1];double c=succProb[i]; v[a].push_back(make_pair(b,c)); v[b].push_back(make_pair(a,c)); } priority_queue<pair<double,int> >q; q.push(make_pair(1.0,start)); while(!q.empty()){ int top=q.top().second; q.pop(); for(int i=0;i<v[top].size();i++){ int back=v[top][i].first; double w=v[top][i].second; if(dist[top]*w>dist[back]){ dist[back]=dist[top]*w; q.push(make_pair(dist[back],back)); } } } return dist[end]; } };