summaryrefslogtreecommitdiff
path: root/Es5.cpp
blob: 8f6fb4820dfddd2e1406b6f73039248846c07595 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#define BIANCO 0  //Non Visitato
#define NERO 2   //Visitato
#define GRIGIO 1 //Non Finito
#define INF 999999
#include <vector>
#include <fstream>
#include <queue>
#define MAXN 9999
#define INDEF -1
#include <stack>
using namespace std;
typedef pair <int,int> p;
struct nodo{
	vector<int> adj;
	vector<int> p;
};

int main(int argc, char** argv) {
	int v,e;
	int sorgente;
	nodo no[v];
	
	priority_queue<p> Q;
	int peso[v];
	Q.push(p(0,sorgente));
	
	while(!Q.empty())
	{
		pair <int,int> a=Q.top();
		Q.pop();
		if (a.first > peso[a.second])
		continue;
		
		for (int i=0;i<no[a.second].adj.size();i++)
		{
			if (peso[no[a.second].adj[i]]>a.first+ no[a.second].p[i])
			{
				peso[no[a.second].adj[i]]=a.first + no[a.second].p[i];
				Q.push(p(peso[no[a.second].adj[i]],no[a.second].adj[i]));
			}
		}
		
	}
	return 0;
}