Title 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
1 S
3 1
5
0 S
1 3
1 4
2 5
3 5
1 5
Sample output
Sample Output
3.41
Data range and Tips
Data Size & Hint
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5 using namespacestd;6 Doubledb_maxn=127;7 Doublemaxn=127;8 structnode9 {Ten Doublex; One Doubley; A}a[1001]; - Doubledis[1001]; - intvis[1001]; the intN; - Doublemap[101][101]; - voidDijkstra (intu) - { +memset (Vis,0,sizeof(Vis)); - for(intI=1; i<=n;i++) + { Adis[i]=Map[u][i]; at } -dis[u]=0; -vis[u]=1; - for(intI=1; i<n;i++) - { - Doubleminn=99999999; in intk=-1; - for(intj=1; j<=n;j++) to { + if((Dis[j]<=minn) &&vis[j]==0) - { theminn=Dis[j]; *k=J; $ }Panax Notoginseng } -vis[k]=1; the for(intj=1; j<=n;j++) + { A if((Dis[j]>=dis[k]+map[k][j]) &&vis[j]==0) thedis[j]=dis[k]+Map[k][j]; + } - } $ } $ intMain () - { -memset (MAP,DB_MAXN,sizeof(map)); thememset (DIS,DB_MAXN,sizeof(DIS)); -scanf"%d",&n);Wuyi for(intI=1; i<=n;i++) the { -scanf"%LF%LF",&a[i].x,&a[i].y); Wu //a[i].cd=sqrt ((POW (ABS (x), 2)) + (POW (abs (y), 2 ))); - } About intm; $scanf"%d",&m); - for(intI=1; i<=m;i++) - { - intp,q; Ascanf"%d%d",&p,&q); + DoubleY=sqrt (Pow (a[p].x-a[q].x,2) +pow (A[P].Y-A[Q].Y,2)); themap[p][q]=y; -map[q][p]=y; $ } the intu,v; thescanf"%d%d",&u,&v); the Dijkstra (u); theprintf"%0.2LF", Dis[v]); - return 0; in}
2602 Shortest path Problem Dihstra algorithm