int finallist[10]={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},top=-1,matrix[10][10],transpose[10][10],n,start;;
int visited(int x)
{
int i;
for(i=0;i<n;i++)
{
if(finallist[i]==x)
return 1;//it is visited
}
return 0;//not visited
}
void dfs(int source)
{
int i,j;
if(visited(source)==0)
{
finallist[++top]=source;//if not visited then add to final list
printf(" [%d], ",finallist[top]+1);//print strongly connected components
}
for(i=0;i<n;i++)
if(transpose[source][i]==1 && visited(i)==0)
{
dfs(i); //recursion to add nodes to final list
}
printf("\n"); //stop printing since no more SCC are found
// look for those nodes which are not reachable
for(i=0;i<n;i++)
if(visited(i)==0)
{
dfs(i);
}
}
int main()
{
char x[2],i,j;
printf("\nEnter the number of vertices (Maximum is 10) :- ");
scanf("%d",&n);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
printf("Is %d connected to %d? (y/n)",i+1,j+1);
scanf("%s",x);
if((x[0] == 'y' || x[0] == 'Y') && i!=j)
matrix[i][j]=1;//there is connection
else
matrix[i][j]=0;//no connection
}
//finding transpose of given graph
for(i=0;i<n;i++)
for(j=0;j<n;j++)
transpose[i][j]=matrix[j][i];
printf("Strongly connected components are :-\n");
dfs(0);//find depth first search
return 0;
}```