Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define M 1000
- vector<int>adj[M];
- bool visited[M];
- int a[105][105];
- void bfs(int s)
- {
- visited[s]=true;
- queue<int>q;
- q.push(s);
- while(!q.empty())
- {
- int u=q.front();
- q.pop();
- for(int i=0;i<adj[u].size();i++)
- {
- if(visited[adj[u][i]]==false)
- {
- int v=adj[u][i];
- // cout<<v<<endl;
- visited[v]=true;
- q.push(v);
- }
- }
- }
- }
- int main()
- {
- int t,kase=0;;
- cin>>t;
- while(kase<t)
- {
- int n,i,j;
- scanf("%d",&n);
- /* //int a[n+5][n+5];
- //if(n==1)
- {
- if(k==1)
- {
- printf("+-+\n")
- printf("| N |\n");
- }
- }*/
- for(i=0;i<n;i++)
- {
- for(j=0;j<n;j++)
- {
- int k;
- cin>>k;
- if(k==1){
- adj[i].push_back(j);
- //cout<<k<<endl;
- }
- }
- }
- vector<int>v[105];
- for(j=1;j<n;j++)
- {
- //cout<<j<<endl;
- memset(visited,false,sizeof visited);
- visited[j]=true;
- bfs(0);
- for(i=0;i<n;i++)
- {
- if(visited[i]==false)
- {
- v[j].push_back(i);
- a[j][i]=1;
- }
- }
- }
- for(i=0;i<n;i++)
- {
- a[0][i]=1;
- }
- for(i=1;i<n;i++)
- {
- a[i][i]=1;
- }
- int k;
- printf("Case %d:\n",kase+1);
- for(i=0;i<n;i++)
- {
- int x=2*n+1;
- printf("+");
- for(k=0;k<2*n-1;k++)
- printf("-");
- printf("+\n");
- //cout<<endl;
- for(j=0;j<n;j++)
- {
- printf("|");
- if(a[i][j]==1)
- {
- printf("Y");
- }
- else
- {
- printf("N");
- }
- }
- printf("|\n");
- } //cout<<endl;
- printf("+");
- for(k=0;k<2*n-1;k++)
- printf("-");
- printf("+\n");
- for(i=0;i<M;i++)
- {
- adj[i].clear();
- }
- memset(a,0,sizeof a);
- kase++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment