Cod sursa(job #1045926)

Utilizator gorgorothPurice Ciprian gorgoroth Data 2 decembrie 2013 12:53:31
Problema Arbore partial de cost minim Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.72 kb
#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;
}
}