Saleh127

UVA 11902

Jun 24th, 2021
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5.  
  6. vector<ll>g[2000];
  7. bool v[2000],u[2000];
  8. ll a[200][200];
  9. ll cc;
  10.  
  11. void dfs(ll in)
  12. {
  13. u[in]=1;
  14. for(auto dd:g[in])
  15. {
  16. if(u[dd]==0)
  17. {
  18. dfs(dd);
  19. }
  20. }
  21. }
  22.  
  23. void dfs1(ll in)
  24. {
  25. if(in==cc) return;
  26.  
  27. v[in]=1;
  28.  
  29. for(auto dd:g[in])
  30. {
  31. if(v[dd]==0)
  32. {
  33. dfs1(dd);
  34. }
  35. }
  36. }
  37.  
  38. int main()
  39. {
  40. ios_base::sync_with_stdio(0);
  41. cin.tie(0);
  42. cout.tie(0);
  43.  
  44. test
  45. {
  46.  
  47. ll n,m,i,j,k,l;
  48.  
  49. cin>>n;
  50.  
  51. for(i=0; i<n+5; i++)
  52. {
  53. g[i].clear();
  54. }
  55.  
  56. cout<<"Case "<<cs<<":"<<endl;
  57.  
  58. for(i=0; i<n; i++)
  59. {
  60. for(j=0; j<n; j++)
  61. {
  62. cin>>k;
  63. if(k) g[i].push_back(j);
  64. }
  65. }
  66.  
  67. memset(u,0,sizeof u);
  68. memset(a,0,sizeof a);
  69.  
  70. dfs(0);
  71.  
  72.  
  73. for(i=0; i<n; i++)
  74. {
  75. cc=i;
  76. memset(v,0,sizeof v);
  77. dfs1(0);
  78.  
  79. for(j=0; j<n; j++)
  80. {
  81. if(u[j] && v[j]==0)
  82. {
  83. a[i][j]=1;
  84. }
  85. }
  86. }
  87.  
  88. cout<<"+";
  89. for(k=0; k<(2*n-1); k++) cout<<"-";
  90. cout<<"+"<<endl;
  91.  
  92. for(i=0; i<n; i++)
  93. {
  94. cout<<"|";
  95.  
  96. for(j=0; j<n; j++)
  97. {
  98. if(a[i][j]==1) cout<<"Y|";
  99. else cout<<"N|";
  100. }
  101. cout<<endl;
  102.  
  103. cout<<"+";
  104. for(k=0; k<(2*n-1); k++) cout<<"-";
  105. cout<<"+"<<endl;
  106. }
  107. }
  108.  
  109. return 0;
  110. }
  111.  
Advertisement
Add Comment
Please, Sign In to add comment