include
using namespace std;
define INF 1000
define MAX 10000
struct node
{
int distance;
int check;
};
void change_dist(int start, struct node dist[], short int a[1000][1000], int n)
{
for(int l = 0; l < n; l++) {
if(a[start][l] != INF && dist[l].check != 1) {
if(dist[l].distance > a[start][l]) {
dist[l].distance = a[start][l];
}
}
}
}
int find_min(struct node dist[], int n)
{
int d = MAX;
int index;
for(int i = 0; i < n; i++) {
if(dist[i].check == 0 && dist[i].distance < d) {
index = i;
d = dist[i].distance;
}
}
return index;
}
int main()
{
int test;
int n;
int price_per_furlong;
int no_of_streets;
cin >> test;
for(int i = 0 ; i < test; i++) {
short int a[1000][1000];
cin >> price_per_furlong;
cin >> n;
cin >> no_of_streets;
int total = 0;
struct node dist[n];
for(int l = 0; l < n; l++) {
for(int j = 0; j < n; j++) {
a[l][j] = INF;
}
dist[l].distance = INF;
dist[l].check = 0;
}
for(int j = 0; j < no_of_streets; j++) {
int x,y,z;
cin >> x >> y >> z;
a[x-1][y-1] = z;
a[y-1][x-1] = z;
}
dist[0].distance = 0;
int start = 0;
for(int k = 0; k < n; k++) {
total = total + dist[start].distance;
dist[start].check = 1;
change_dist(start,dist,a,n);
start = find_min(dist,n);
}
cout << price_per_furlong*total << endl;
}
return 0;
}
why this code is wrong????????
///giving wrong answer