Umesh Prog7
Umesh Prog7
Jadhav
Practical No : 7(C)
Batch : S1
Roll No : 20
Branch : AI&DS
/*You have a business with several offices; you want to lease phone lines to connect them up with
each other; and the phone company charges different amounts of money to connect different pairs
of cities. You want a set of lines that connects all your offices with a minimum total cost. Solve the
problem by suggesting appropriate data structures.*/
#include <iostream>
#include <limits.h>
int main() {
char op;
cin >> n;
cost[i][j] = -1;
cout << "Do you want an edge between " << i + 1 << " and " << j + 1 << " (y/n): ";
min = INT_MAX;
if (visit[i] == 1) {
min = cost[i][j];
row = i;
col = j;
mincost += min;
cout << "Edge selected: " << row + 1 << " -> " << col + 1 << " (Weight: " << min << ")\n";
return 0;
}
OUTPUT :
(base) computer@computer-ThinkCentre-neo-50s-Gen-3:~$ cd ..
Enter weight: 5
Enter weight: 10
Enter weight: 4
Enter weight: 8
Minimum Cost: 17