Maruf_Hasan

dom 2

Jan 31st, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define M 1000
  4. vector<int>adj[M];
  5. bool visited[M];
  6. int a[105][105];
  7. void bfs(int s)
  8. {
  9. visited[s]=true;
  10. queue<int>q;
  11. q.push(s);
  12. while(!q.empty())
  13. {
  14. int u=q.front();
  15. q.pop();
  16. for(int i=0;i<adj[u].size();i++)
  17. {
  18. if(visited[adj[u][i]]==false)
  19. {
  20. int v=adj[u][i];
  21. // cout<<v<<endl;
  22. visited[v]=true;
  23. q.push(v);
  24. }
  25. }
  26. }
  27.  
  28. }
  29.  
  30. int main()
  31. {
  32. int t,kase=0;;
  33. cin>>t;
  34. while(kase<t)
  35. {
  36. int n,i,j,k;
  37. scanf("%d",&n);
  38. //int a[n+5][n+5];
  39. if(n==1)
  40. {
  41. cin>>k;
  42. printf("Case %d:\n",kase+1);
  43. if(k==0)
  44. {
  45. printf("+-+\n");
  46. printf("|N|\n");
  47. printf("+-+\n");
  48. }
  49. else
  50. {
  51. printf("+-+\n");
  52. printf("|N|\n");
  53. printf("+-+\n");
  54. }
  55. kase++;
  56.  
  57. }
  58. else
  59. {
  60.  
  61. for(i=0;i<n;i++)
  62. {
  63. for(j=0;j<n;j++)
  64. {
  65. cin>>k;
  66. if(k==1){
  67. adj[i].push_back(j);
  68. //cout<<k<<endl;
  69.  
  70. }
  71. }
  72. }
  73. vector<int>v[105];
  74. for(j=1;j<n;j++)
  75. {
  76. //cout<<j<<endl;
  77. memset(visited,false,sizeof visited);
  78. visited[j]=true;
  79. bfs(0);
  80. for(i=0;i<n;i++)
  81. {
  82. if(visited[i]==false)
  83. {
  84. v[j].push_back(i);
  85. a[j][i]=1;
  86. }
  87. }
  88. }
  89. for(i=0;i<n;i++)
  90. {
  91. a[0][i]=1;
  92. }
  93. for(i=1;i<n;i++)
  94. {
  95. a[i][i]=1;
  96. }
  97.  
  98. printf("Case %d:\n",kase+1);
  99. for(i=0;i<n;i++)
  100. {
  101. int x=2*n+1;
  102. printf("+");
  103. for(k=0;k<2*n-1;k++)
  104. printf("-");
  105. printf("+\n");
  106. //cout<<endl;
  107. for(j=0;j<n;j++)
  108. {
  109. printf("|");
  110. if(a[i][j]==1)
  111. {
  112. printf("Y");
  113. }
  114. else
  115. {
  116. printf("N");
  117. }
  118. }
  119.  
  120. printf("|\n");
  121.  
  122.  
  123. } //cout<<endl;
  124. printf("+");
  125. for(k=0;k<2*n-1;k++)
  126. printf("-");
  127. printf("+\n");
  128.  
  129. for(i=0;i<M;i++)
  130. {
  131. adj[i].clear();
  132. }
  133. memset(a,0,sizeof a);
  134. kase++;
  135. }
  136. }
  137. return 0;
  138. }
Add Comment
Please, Sign In to add comment