DijKstra
struct Edge {
int to;
int l;
Edge(int x,int y):to(x),l(y) {}
};
struct Point {
int n;
int distance;
Point(int a,int b):n(a),distance(b) {};
bool operator < (const Point & a) const {
return distance>a.distance;
}
};
vector<Edge> graph[Max];
int dis[Max];
void Dijkstra(int s) {
priority_queue<Point> q;
dis[s]=0;
q.push(Point(s,dis[s]));
while(!q.empty()) {
int u=q.top().n; //离源点最近的点
q.pop();
for(int i=0; i<graph[u].size(); i++) { //遍历该点所有的连接点,修改最短距离,并从下一个最近点开始。
int v=graph[u][i].to;
int l=graph[u][i].l;
if(dis[u]+l<dis[v]) {
dis[v]=dis[u]+l;
q.push(Point(v,dis[v]));
}
}
}
return ;
}
int to;
int l;
Edge(int x,int y):to(x),l(y) {}
};
struct Point {
int n;
int distance;
Point(int a,int b):n(a),distance(b) {};
bool operator < (const Point & a) const {
return distance>a.distance;
}
};
vector<Edge> graph[Max];
int dis[Max];
void Dijkstra(int s) {
priority_queue<Point> q;
dis[s]=0;
q.push(Point(s,dis[s]));
while(!q.empty()) {
int u=q.top().n; //离源点最近的点
q.pop();
for(int i=0; i<graph[u].size(); i++) { //遍历该点所有的连接点,修改最短距离,并从下一个最近点开始。
int v=graph[u][i].to;
int l=graph[u][i].l;
if(dis[u]+l<dis[v]) {
dis[v]=dis[u]+l;
q.push(Point(v,dis[v]));
}
}
}
return ;
}