Program for queue and vector, C/C++ Programming

Assignment Help:

#include

#include

#include

using namespace std;

#define MAX 5

#define INF (1<<20)

#define DEBUG if(0)

#define pii pair< int, int >

#define pb(x) push_back(x)

class Node

{

int id:

int p[1][2];

class Node *next[5];

 bool operator() (const pii &a, const pii &b)

{

        return a.second > b.second;

 } ;

priority_queue< pii, vector< pii >, Node > Q;

vector< pii > G[MAX];

int D[MAX];

bool F[MAX];

int main()

{

int i, u, v, w, sz, nodes, edges, starting;

// create graph

cin >> nodes >> edges;

for(i=0; i

{

cin>> u >> v >> w;

G[u].pb(pii(v, w));

G[v].pb(pii(u, w)); // for undirected

}

cin >> starting;

for(i=1; i<=nodes; i++) D[i] = INF;

D[starting] = 0;

Q.push(pii(starting, 0));

while(!Q.empty())

{

   u = Q.top().first;

   Q.pop();

   if(F[u]) continue;

  sz = G[u].size();

  DEBUG cout<<"visiting from "<< u;

  for(i=0; i

{

        v = G[u][i].first;

         w = G[u][i].second;

         if(!F[v] && D[u]+w < D[v])

                {

                 DEBUG cout<<  v;

                 D[v] = D[u] + w;

                 Q.push(pii(v, D[v]));

                 }

         }

DEBUG cout << "\n";

F[u] = 1;

}

for(i=1; i<=nodes; i++)

cout << "Node"<< i<< "min weight"<<  D[i]);

return 0;

}


Related Discussions:- Program for queue and vector

Application for tag in the forest game, Your program should use the Free Pa...

Your program should use the Free Pascal compiler or the Lazarus IDE described in CSC 540. When you hand in your assignment to the digital dropbox, it should be a .PAS file, not zip

Create program to prints out the value of a variable, Here is a short progr...

Here is a short program. It prints out the value of a variable "x". Ernie and Bert disagree about what will be printed: Ernie says, the value gets changed in "changeX" so it will p

Explain reference oddities, Reference Oddities A reference variable can...

Reference Oddities A reference variable can demote to any integer variable, be it in an array or a member variable from structure or class. Reference variables can demote to co

I need profile and optimize a c++ library for speed, I need Profile and opt...

I need Profile and optimize a C++ library for speed Project Description: Optimize and profile an existing C++ library for speed. This library uses OpenMP and OpenCV and C+

Graphical user interface designed for the output peripherals, Introduction ...

Introduction to I/O interfacing, discuss microcontrollers applications in industry. Detailed product design specifications that have sections on both hardware and software inclu

Lcm code, full coding for lcm in c++

full coding for lcm in c++

Loop, wap to count the numof string present in a word

wap to count the numof string present in a word

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd