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

#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;

}

Posted Date: 3/14/2013 3:27:28 AM | Location : United States







Related Discussions:- Program for queue and vector, Assignment Help, Ask Question on Program for queue and vector, Get Answer, Expert's Help, Program for queue and vector Discussions

Write discussion on Program for queue and vector
Your posts are moderated
Related Questions
When I develop a destructor, do I require to explicitly call the destructors for my member objects?

Functions Overloading This a capability in which a C++ program can have several functions performing similar tasks on different data types. When an overloaded function is calle

write a c program chat illustrates the creation of child process using fork system call. One process finds sum of even series and other process finds sum of odd series.

The concept of a string in C is difficult, because a string is a collection of characters stored in memory terminated by a NULL string i.e. \0. Let us consider the string Hello. Th

I''m having trouble with my C code to red from a Hash table. Not sure what it is I''m doing wrong and stumped. I need to get it figured out by tomorrow at 4:00 p.m. Eastern time. C

You're going to simulate a metropolitan subway train.  The train system will start out at Station #1, or Home  Station, and will service multiple stations along its route.

A: 1.      By using const protects you against programming errors which inadvertently alter data. 2.      By using const allows function to procedure const and non-const actu

Question: a) Give two uses of NFS. b) Give one advantage of using NFS. c) Explain the following lines as they would be interpreted in the /etc/exports file i. /usr/local

C Program for SORTING # include stdio.h> void main() {           char a;           int *p;           int i,j,temp;           clrscr();           p=&i;

a program to find the area under curve y=f(x) between x=a and x=b,integrate y=f(x) between the limits of a and b.   #include float start_point, /* G