Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- bool visited[10];
- int n;
- void recur(int pos,int graph[10][10])
- {
- int i;
- if(visited[pos]==1)
- return;
- else
- {
- visited[pos]=1;
- // cout<<pos+1<<' ';
- for(i=0; i<n; i++)
- {
- if(graph[pos][i]==1)
- recur(i,graph);
- }
- }
- }
- int main()
- {
- int graph[10][10],i,j,k,x,y;
- cin>>n;
- for(i=0; i<n; i++)
- {
- for(j=0; j<n; j++)
- {
- cin>>graph[i][j];
- }
- }
- //memset(A,0,sizeof A);
- int count=0,max=0;
- for(k=0; k<n; k++)
- {
- memset(visited,0,sizeof(visited));
- visited[k]=-1;
- count=0;
- for(j=0; j<n; j++)
- {
- // cout<<"i is "<<j<<endl;
- if(visited[j]==0)
- {
- count++;
- recur(j,graph);
- }
- }
- // cout<<"k="<<k<<"count= "<<count<<endl;
- if(count>1)
- {
- if(max<count)
- max=count;
- cout<<count<<endl;
- }
- }
- cout<<max<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement