Maruf_Hasan

dominator 1

Jan 31st, 2019
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 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;
  37. scanf("%d",&n);
  38. /* //int a[n+5][n+5];
  39. //if(n==1)
  40. {
  41. if(k==1)
  42. {
  43. printf("+-+\n")
  44. printf("| N |\n");
  45.  
  46. }
  47. }*/
  48. for(i=0;i<n;i++)
  49. {
  50. for(j=0;j<n;j++)
  51. {
  52. int k;
  53. cin>>k;
  54. if(k==1){
  55. adj[i].push_back(j);
  56. //cout<<k<<endl;
  57.  
  58. }
  59. }
  60. }
  61. vector<int>v[105];
  62. for(j=1;j<n;j++)
  63. {
  64. //cout<<j<<endl;
  65. memset(visited,false,sizeof visited);
  66. visited[j]=true;
  67. bfs(0);
  68. for(i=0;i<n;i++)
  69. {
  70. if(visited[i]==false)
  71. {
  72. v[j].push_back(i);
  73. a[j][i]=1;
  74. }
  75. }
  76. }
  77. for(i=0;i<n;i++)
  78. {
  79. a[0][i]=1;
  80. }
  81. for(i=1;i<n;i++)
  82. {
  83. a[i][i]=1;
  84. }
  85.  
  86. int k;
  87. printf("Case %d:\n",kase+1);
  88. for(i=0;i<n;i++)
  89. {
  90. int x=2*n+1;
  91. printf("+");
  92. for(k=0;k<2*n-1;k++)
  93. printf("-");
  94. printf("+\n");
  95. //cout<<endl;
  96. for(j=0;j<n;j++)
  97. {
  98. printf("|");
  99. if(a[i][j]==1)
  100. {
  101. printf("Y");
  102. }
  103. else
  104. {
  105. printf("N");
  106. }
  107. }
  108.  
  109. printf("|\n");
  110.  
  111.  
  112. } //cout<<endl;
  113. printf("+");
  114. for(k=0;k<2*n-1;k++)
  115. printf("-");
  116. printf("+\n");
  117.  
  118. for(i=0;i<M;i++)
  119. {
  120. adj[i].clear();
  121. }
  122. memset(a,0,sizeof a);
  123. kase++;
  124. }
  125. return 0;
  126. }
Advertisement
Add Comment
Please, Sign In to add comment