Graf orientat tare conex

 

#include<fstream.h>
#include<conio.h>
int s[50],a[50][50],n,suc[50],pred[50],i,j;
void citire(char fis[20],int a[50][50],int&n)
{
fstream f(fis,ios::in);
int i,j;
f>>n;
while(f>>i>>j) a[i][j]=1;
f.close();
}

void df1 (int nod)
{
int k;
suc[nod]=i;

for (k=1;k<=n;k++)
if ((a[nod][k]==1) && (suc[k]==0))
df1(k);
}
void df2(int nod)
{
int k;
pred[nod]=i;
for (k=1;k<=n;k++)
if((a[k][nod]==1)&&(pred[k]==0))
df2(k);
}
void main()
{
citire("fis.txt",a,n);
cout<<"nodul de pornire:";cin>>i;
suc[i]=pred[i]=i;
df1(i);df2(i);
for(j=1;j<=n;j++)
if((suc[j]==pred[j])&&(suc[j]==i))
cout<<j<<" ";
getch();
}

{joscommentenable}