Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool visited[10];
  5. int n;
  6.  
  7. void recur(int pos,int graph[10][10])
  8. {
  9. int i;
  10. if(visited[pos]==1)
  11. return;
  12. else
  13. {
  14. visited[pos]=1;
  15. // cout<<pos+1<<' ';
  16. for(i=0; i<n; i++)
  17. {
  18. if(graph[pos][i]==1)
  19. recur(i,graph);
  20. }
  21. }
  22. }
  23.  
  24. int main()
  25. {
  26. int graph[10][10],i,j,k,x,y;
  27. cin>>n;
  28. for(i=0; i<n; i++)
  29. {
  30. for(j=0; j<n; j++)
  31. {
  32. cin>>graph[i][j];
  33. }
  34. }
  35. //memset(A,0,sizeof A);
  36. int count=0,max=0;
  37. for(k=0; k<n; k++)
  38. {
  39. memset(visited,0,sizeof(visited));
  40. visited[k]=-1;
  41. count=0;
  42. for(j=0; j<n; j++)
  43. {
  44. // cout<<"i is "<<j<<endl;
  45. if(visited[j]==0)
  46. {
  47. count++;
  48. recur(j,graph);
  49. }
  50. }
  51. // cout<<"k="<<k<<"count= "<<count<<endl;
  52. if(count>1)
  53. {
  54. if(max<count)
  55. max=count;
  56. cout<<count<<endl;
  57. }
  58.  
  59. }
  60. cout<<max<<endl;
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement