Sample Input 1:
4 3 11 5
1 2 2
1 4 2
1 G1 4
1 G2 3
2 3 2
2 G2 1
3 4 2
3 G3 2
4 G1 3
G2 G1 1
G3 G2 2
Sample Output 1:
G1
2.0 3.3
Sample Input 2:
2 1 2 10
1 G1 9
2 G1 20
Sample Output 2:
No Solution
题解
最短路径问题,使用二维数组存储图结构,将站点拼接到房屋节点之后,使用Dijkstra求每个站点的距离d[]
数组,每求出一个新的d[]
之后就视情况更新结果
#include <iostream>
#include <string>
using namespace std;
const int MAXV = 1020;
const int inf = 999999999;
int n,m,k,d;
int G[MAXV][MAXV];
int mini_d;
int index_g = -1;
double average_d = 0;
int gd[MAXV];
int visit[MAXV] = {
false};
int main(){
int temp_from,temp_to,temp_d;
string temp_from_s,temp_to_s;
fill(G[0],G[0]+MAXV*MAXV,-1);
cin >> n