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
| struct edge{ int to; int length; edge(int t, int l): to(t), length(l){} };
struct point{ int number; int distance; point(int n, int d): number(n), distance(d) {} bool operator<(const point& p) const{ return distance > p.distance; } };
void dijskstra(int s){ priority_queue<point> qu; dis[s] = 0; qu.push(point(s,dis[s])); while(!qu.empty){ int cur = qu.top().number; qu.pop(); for(int i = 0; i < graph[cur].size(); ++i){ int v = graph[cur][i].to; int d = graph[cur][i].length; if(dis[v] > dis[u] + d){ dis[v] = dis[u] + d; qu.push(point(u, dis[v])); } } } return; }
|
This is copyright.