2602 Shortest Path problem
time limit: 1 sspace limit: 32000 KBtitle level: Golden Gold SolvingTitle Description
Description
There are n dots (n<=100) on the plane, and the coordinates of each point are between -10000~10000. Some of these points have connections between them. If there is a connection, it means that it is possible to reach another point from one point, that is, a path between two points and a straight distance between two points. The task now is to find the shortest path from one point to another.
Enter a description
Input Description
The first behavior is an integer n.
Line 2nd to line n+1 (total n rows), two integers x and y per line, describes the coordinates of a point.
The n+2 acts as an integer m, which indicates the number of lines in the graph.
Thereafter the M-line, each line describes a connection, consisting of two integers I and j, which indicates that there is a connection between the point I and the J-point.
Last line: Two integers s and T, representing the source and target points, respectively.
Output description
Output Description
Only one row, a real number (reserved two decimal places), representing the shortest path length from S to T.
Sample input
Sample Input
5
0 0
2 0
2 2
0 2
3 1
5
1 2
1 3
1 4
2 5
3 5
1 5
Sample output
Sample Output
3.41
Hit a water problem.
1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <cmath>5#include <iostream>6 using namespacestd;7 #defineN 1018 #defineB (i) i*i9 DoubleDis[n][n];Ten structnode{ One intx, y; A}q[ -*N]; - DoubleRunintIintj) { - intW=abs (Max (q[i].x,q[j].x)-min (q[i].x,q[j].x)); the intH=abs (Max (Q[I].Y,Q[J].Y)-min (q[i].y,q[j].y)); - returnsqrt (b (h) +B (w)); - } - intMain () { + intNm from, to; -scanf"%d",&n); + for(intI=1; i<=n;i++){ Ascanf"%d%d",&q[i].x,&q[i].y); at } -scanf"%d",&m); -memset (DIS,0x7f,sizeofdis); - for(intI=1; i<=m;i++){ -scanf"%d%d",& from,&to ); -dis[ from][to]=dis[to][ from]=run ( from, to); in } - for(intk=1; k<=n;k++) to for(intI=1; i<=n;i++) + for(intj=1; j<=n;j++) - if(dis[i][j]>dis[i][k]+Dis[k][j]) thedis[i][j]=dis[i][k]+Dis[k][j]; *scanf"%d%d",& from,&to ); $printf"%.2lf\n", dis[ from][to]); Panax Notoginseng return 0; -}
2602 Shortest Path problem