Pagini recente » Cod sursa (job #194641) | Cod sursa (job #1787760) | Cod sursa (job #1386150) | Cod sursa (job #1941793) | Cod sursa (job #1045926)
#include <fstream>
using namespace std;
ifstream fin ("date.in");
ofstream fout ("date.out");
int a,b,v[100],k,m,i,n,s[100],u;
struct muchie {int x,y,cost;};v[100];
int comp (const muchie &a, const muchie & b)
{return a.cost<b.cost;}
int main()
{
int x,y,z,j,w;
while (fin>>x>>y>>z)
{v[k].x=x;
v[k].y=y;
v[k].cost=z;
k++;
}
sort (v,v+m,comp)
ms=0;
for (i=1;<=n;i++)
s[i]=i;
while (ms<n-1)
{
while (a[v[i].x]==s[v[i].y])
i++;
fout<<v[i].x<<' '<<v[i].y<<endl;
ms++;
ct+=v[i].cost;
if (s[v[i].x]<s[v[i].y])
{
u=s[v[i].x];
w=s[v[i].y];
}
else
{
u=s[v[i].y];
w=s[v[i].x];
}
for (j=1;j<=n;j++)
if (s[j]==w)
s[j]=w;
}
}