C++问题谁能帮忙做一下

来源:百度知道 编辑:UC知道 时间:2024/09/18 04:22:40
如果以无向网表示N个城市之间通信网络的建设计划,顶点表示城市,边上的权表示该线路的造价,设计一个方案,使这个通信网的总造价最低。
能不能帮忙做一下啊

#include<stdio.h>
#define MaxVerNum 100
#define MAX 10000

typedef struct{
char *city[MaxVerNum];
int edges[MaxVerNum][MaxVerNum];
int n,e;
int price;
}MGraph; //接矩阵

void CreatGraph(MGraph *G)
{
int i,j,k,w;
printf("please input the number of cities(n) and routes(e):");

scanf("%d,%d",&(G->n),&(G->e));

printf("please input the name of cities:\n");
for(i=0;i<G->n;i++)
G->city[i]=(char *)malloc(MaxVerNum);
for(i=0;i<G->n;i++)

scanf("%s",G->city[i]);

for(i=0;i<G->n;i++)
for(j=0;j<G->n;j++)
{
if(i==j)
G->edges[i][j]=0;
else G->edges[i][j]=MAX;
}

for(k=1;k<=G->e;k++)
{
printf("the %d's city price is:",k);
sca