Codul pruffer


#include<iostream.h>
#include<conio.h>
int t[50],pt[50],i,j,k,n,gasit;

void main()
{ cout<<"n=";cin>>n;
for(i=1;i<=n-2;i++)
{cout<<"pt["<<i<<"]=";
cin>>pt[i];
}
pt[n-1]=n;
for(i=1;i<=n-1;i++)
{k=1;
do
{gasit=0;
for(j=1;j<=i-1;j++)
if(t[j]==k) gasit=1;
if(!gasit)
for(j=i;j<=n-1;j++)
if(pt[j]==k) gasit=1;
if(gasit) k++;
} while(gasit);
t[i]=k;
}
for(i=1;i<=n-1;i++) cout<<t[i]<<" ";
cout<<endl;
getch();
}