|
| 1 | +#include <iostream> |
| 2 | +#include <cmath> |
| 3 | +#include <string.h> |
| 4 | +#include <queue> |
| 5 | +#include <iomanip> // std::setprecision |
| 6 | + |
| 7 | +using namespace std; |
| 8 | + |
| 9 | +double fs, gs; |
| 10 | +const int MAXN = 2000; |
| 11 | + |
| 12 | +int N; |
| 13 | +double loc[MAXN][2]; |
| 14 | + |
| 15 | +double graph[MAXN][MAXN]; |
| 16 | + |
| 17 | +double euc_dis(double lat1, double lng1, double lat2, double lng2){ |
| 18 | + return sqrt((lat1-lat2)*(lat1-lat2) + (lng1-lng2)*(lng1-lng2)); |
| 19 | +} |
| 20 | + |
| 21 | + |
| 22 | +double dis[MAXN]; |
| 23 | +bool visited[MAXN]; |
| 24 | +double tmp[MAXN]; |
| 25 | +int track[MAXN]; |
| 26 | +const double INF = 99999999999.9; |
| 27 | + |
| 28 | +void dij(int start, int end){ |
| 29 | + for(int i=0; i<MAXN; i++){ |
| 30 | + dis[i] = INF; |
| 31 | + } |
| 32 | + memset(visited, 0, sizeof(visited)); |
| 33 | + |
| 34 | + dis[start] = 0; |
| 35 | + track[0] = -1; |
| 36 | + |
| 37 | + while(1){ |
| 38 | + double t = INF; |
| 39 | + int cur = -1; |
| 40 | + for(int i=0; i<=N+1; i++){ |
| 41 | + if(dis[i]<t && visited[i]==false){ |
| 42 | + cur = i; |
| 43 | + t = dis[i]; |
| 44 | + } |
| 45 | + } |
| 46 | + if(cur==-1)break; |
| 47 | + |
| 48 | + int update_from = -1; |
| 49 | + for(int i=0; i<MAXN; i++){ |
| 50 | + if(graph[cur][i]!=INF && visited[i]==false && dis[cur]+graph[cur][i] < dis[i]){ |
| 51 | + dis[i] = dis[cur] + graph[cur][i]; |
| 52 | + update_from = i; |
| 53 | + track[i] = cur; |
| 54 | + } |
| 55 | + } |
| 56 | + visited[cur] = true; |
| 57 | + |
| 58 | + } |
| 59 | + |
| 60 | + |
| 61 | + vector<int> ans; |
| 62 | + int pos = end; |
| 63 | + while(pos!=-1){ |
| 64 | + ans.push_back(pos); |
| 65 | + pos = track[pos]; |
| 66 | + } |
| 67 | + |
| 68 | + cout<<setprecision(8)<<fixed<<dis[end]<<endl; |
| 69 | + cout<<ans.size()-2; |
| 70 | + for(int i=ans.size()-2; i>=1; i--){ |
| 71 | + cout<<" "<<ans[i]; |
| 72 | + } |
| 73 | + cout<<endl; |
| 74 | +} |
| 75 | + |
| 76 | + |
| 77 | +void work(){ |
| 78 | + dij(0, N+1); |
| 79 | +} |
| 80 | + |
| 81 | +int main(){ |
| 82 | + |
| 83 | + cin>>fs>>gs; |
| 84 | + cin>>N; |
| 85 | + |
| 86 | + for(int i=0; i<MAXN; i++){ |
| 87 | + for(int j=0; j<MAXN; j++){ |
| 88 | + graph[i][j ] = INF; |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + for(int i=1; i<=N; i++){ |
| 93 | + cin>>loc[i][0]>>loc[i][1]; |
| 94 | + } |
| 95 | + |
| 96 | + while(1){ |
| 97 | + int from, to; |
| 98 | + cin>>from>>to; |
| 99 | + |
| 100 | + if(from==0 && to==0)break; |
| 101 | + |
| 102 | + graph[from][to] = graph[to][from] = euc_dis(loc[from][0], loc[from][1], loc[to][0], loc[to][1])/gs; |
| 103 | + |
| 104 | + |
| 105 | + } |
| 106 | + |
| 107 | + cin>>loc[0][0]>>loc[0][1]; |
| 108 | + cin>>loc[N+1][0]>>loc[N+1][1]; |
| 109 | + |
| 110 | + for(int i=0; i<=N+1; i++){ |
| 111 | + for(int j=0; j<=N+1; j++){ |
| 112 | + graph[i][j] = graph[j][i] = min(euc_dis(loc[i][0], loc[i][1], loc[j][0], loc[j][1])/fs, graph[j][i]); |
| 113 | + } |
| 114 | + //graph[0][i] = graph[i][0] = euc_dis(loc[0][0], loc[0][1], loc[i][0], loc[i][1])/fs; |
| 115 | + //graph[N+1][i] = graph[i][N+1] = euc_dis(loc[N+1][0], loc[N+1][1], loc[i][0], loc[i][1])/fs; |
| 116 | + } |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | + |
| 121 | + /* |
| 122 | + for(int i=0; i<=N+1; i++){ |
| 123 | + cout<<"node "<<i<<endl; |
| 124 | + for(int j=0; j<=N+1; j++){ |
| 125 | + cout<<graph[i][j]<<" "; |
| 126 | + } |
| 127 | + cout<<endl; |
| 128 | + } |
| 129 | + */ |
| 130 | + work(); |
| 131 | + |
| 132 | + |
| 133 | + |
| 134 | + return 0; |
| 135 | +} |
0 commit comments