PS: It was a review of the graph theory, and finally became a preview, separated a period of time simply, re-learn!
hahaha haha, really dish ah!
single source The shortest path problem is to ask, fix a starting point, and ask for the shortest path to all other points.
The shortest path between two points is to seek, fixed the starting point and end point to find short circuit
There is no fundamental difference between the two, the same complexity
1, single source shortest 1 Bellman-ford algorithm
Core algorithms:
D[i]=min (d[j]+ (weights from vertex j to vertex i edge), D[i])
D "I" indicates the shortest distance from any point to the vertex i
Generally initialized to INF, and then start D "s" to initialize 0.
As long as there is no negative circle (negative circle refers to the two points between the weight of the circle formed by a negative value) Update operation is limited
structEdge//The weight from the vertex from-->to is the cost of the edge{ int from; intto ; intCost ;}; Edge ES[MAXN]; //sideintD[MAXN];//Shortest distanceintV,b;//vertex and number of sides, respectivelyvoidBellmanintS//Recursive from Vertex{ for(intI=0; i<v;i++) D[i]=inf;//The shortest distance of all vertices is set to maximum, excluding the self-loopd[s]=0;//Initialize starting point while(true) { BOOLvis=false; for(intI=0; i<b;i++) {Edge e=Es[i]; if(D[e. from]!=inf&&d[e.to]>d[e. from]+e.cost) {d[e.to]=d[e. from]+E.cost; Update=true; } } if(!update) Break; } }
Forget to find the big guy's detailed thinking, I read and then to fill the
Bellman-ford algorithm: http://www.wutianqi.com/?p=1912
Dijkstra algorithm: http://www.wutianqi.com/?p=1890
Floyd algorithm: http://www.wutianqi.com/?p=1903
Single Source Shortest path (Bellman-ford algorithm +dijkstra algorithm) + any two-point minimum (Floyd-warshall algorithm)