0

Hello ,i have problem with code bellow. every data i enter it show me the weight '0'!

Can you tell me how can i solve this problem?

you should enter number of nods and edges and weight of each edge.

```
#include <stdio.h>
#include <conio.h>
#include <iostream>
#include <Windows.h>
using namespace std;
int perim (int set[],struct krus edge[],int n,int m);
void sort(struct krus ed[],int m);
struct krus{
char v1;
char v2;
int weight;
};
int main()
{
system("cls");
int n,m;
cout<<"Input Num Vertex : ";
cin>>n;
int set[n];
for (int i=0;i<n;i++)
set[i]=i;
cout<<"Input Num Yal : ";
cin>>m;
struct krus edge[20];
for (int i=0;i<m;i++)
{
cout<<" Num V1 : "; cin>>edge[i].v1;
cout<<" Num V2 : "; cin>>edge[i].v2;
cout<<" Weight : "; cin>>edge[i].weight;
}
cout<<"\nWeight Is : "<<perim(set,edge,n,m);
getch();
}
//***********************************************
int perim(int set[],struct krus edge[],int n,int m)
{
int fe=0;
int p=0;
struct krus e;
while (fe<n-1)
{
int y=0;
e.weight=0;
for (int i=0;i<m;i++){
if ((set[edge[i].v1]==0 && set[edge[i].v2]!=0) || (set[edge[i].v2]==0 && set[edge[i].v1]!=0))
{
if(y==0)
{
e=edge[i];
y++;
}
else{
if (e.weight>edge[i].weight)
e=edge[i];}
}}
//**********************************
if (y!=0)
{
p+=e.weight;
cout<<"("<<e.v1<<","<<e.v2<<") => W :"<<e.weight<<"\t";
set[e.v1]=0;
set[e.v2]=0;
fe++;
}
else
break;
}
return p;
}
```