Can you please provide the implementation with use of priority queues. It would be highly helpful if you provide the implementation in java otherwise c++ will also work.
Longest path on a tree
Yes you can implement dijkstra using priority queue. Below is the implementation.
priority_queue< iPair, vector , greater > pq;
vector<int> dist(V, INF);
pq.push(make_pair(0, src));
dist[src] = 0;
while (!pq.empty())
{
int u = pq.top().second;
pq.pop();
list< pair<int, int> >::iterator i;
for (i = adj[u].begin(); i != adj[u].end(); ++i)
{
// Get vertex label and weight of current adjacent
// of u.
int v = (*i).first;
int weight = (*i).second;
if (dist[v] > dist[u] + weight)
{
dist[v] = dist[u] + weight;
pq.push(make_pair(dist[v], v));
}
}
}
Sorry sir it was mistakenly written. Actually I wanted the implementation of above code without the use of priority queues.
Not dijkstra but the code of longest path in a tree using dp without the use of priority queues.
@aman2382000 I do not understand what is real doubt here. Please close this doubt and initiate a new doubt.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.