Problem Description You is the owner of Smallcableco and has purchased the franchise rights for a small town. Unfortunately, lack enough funds to start your business properly and is relying on parts we have found in a old war Ehouse you bought. Among your finds is a single spool of cable and a lot of connectors. You want-to-figure out whether the enough cable to connect every house in town. You had a map of town with the distances for all the paths and you could use the run your cable between the houses. You want to calculate the shortest length of cable you must has to connect all of the houses together.
Input only one town would be given on an input.
The first line gives the length of cable on the spool as a real number.
The second line contains the number of houses, N
The next N lines give the name of each house ' s owner. Each name consists of characters {az,az,09} and contains no whitespace or punctuation.
Next line:m, number of paths between houses
Next M lines in the form
< house name A > < house name B > < distance >
Where The house names match, different names in the list above and the distance are a positive real number. There'll is not paths between the same pair of houses.
Output the output would consist of a single line. If There is not enough cable to connect all of the houses in the town, output
Not enough cable
If there is enough cable and then output
Need < X > miles of Cable
Print X to the nearest tenth of a mile (0.1).
Sample Input
100.0 4 Jones Smiths Howards wangs 5 Jones Smiths 2.0 Jones Howards 4.2 Jones wangs 6.7 Howards wangs 4.0 Smiths wangs 10. 0
Sample Output
Need 10.2 miles of cable This topic a bit of a pit, in the output of%.1LF changed to%.1f on the ....
#include <stdio.h> #include <string.h> double edg[505][505],sum,sum,node[505],inf=1000000.0;
int s[505];
void Set_first (int n) {for (int i=1;i<=n;i++) {s[i]=0; node[i]=inf;
for (int j=i+1;j<=n;j++) Edg[j][i]=edg[i][j]=inf;
}} int Prim (int n,int m) {int tm=m;
Double min;
s[m]=1;sum=0.0;
for (int k=2;k<=n;k++) {min=inf; for (int i=1;i<=n;i++) if (s[i]==0) {if (Node[i]>edg[tm][i]) node[i]=edg[tm][i
]; if (Min>node[i]) {min=node[i];
M=i; }} s[m]=1; Sum+=min;
Tm=m;
} if (sum>=sum) return 1;
return 0;
} int main () {char str[10000][25], name1[25],name2[25];
int n,m,flog,k,x,y;
Double C;
scanf ("%lf%d", &sum,&n);
for (int i=1;i<=n;i++) scanf ("%s", Str[i]);
Set_first (n);
scanf ("%d", &m);
for (int i=0;i<m;i++) { scanf ("%s%s%lf", name1,name2,&c);
for (int j=1;j<=n;j++) if (strcmp (str[j],name1) ==0) x=j;
else if (strcmp (str[j],name2) ==0) y=j;
if (edg[x][y]>c) edg[x][y]=edg[y][x]=c;
} flog=prim (n,1);
if (flog) printf ("Need%.1f miles of cable\n", sum);
else printf ("Not Enough cable\n");
}