bool_bool

UVA11902

Nov 17th, 2019
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.78 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define all(v) v.begin(), v.end()
  5. #define dist2D(x1, y1, x2, y2) ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2))
  6. #define dist3D(x1, y1, z1, x2, y2, z2) ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2))
  7. #define EPS 1e-16
  8. #define endl "\n"
  9. #define FastIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
  10. #define FI freopen("in.txt", "r", stdin)
  11. #define FO freopen("out.txt", "w", stdout)
  12. #define ff first
  13. #define INF 1000000000000000000
  14. #define ld long double
  15. #define ll long long
  16. #define mem(x,y) memset(x, y, sizeof x)
  17. #define mp make_pair
  18. #define msi map<string, int>
  19. #define mii map<int, int>
  20. #define mis map<int, string>
  21. #define MOD 1000000007
  22. #define PI acos(-1.0)
  23. #define PQ priority_queue
  24. #define pb push_back
  25. #define pib pair<int, bool>
  26. #define pii pair<int, int>
  27. #define pll pair<ll, ll>
  28. #define present(c, x) ((c).find(x) != (c).end())
  29. #define sfi(x) scanf("%d", &x)
  30. #define sfii(x,y) scanf("%d %d", &x, &y)
  31. #define sfiii(x,y,z) scanf("%d %d %d", &x, &y, &z)
  32. #define siz(x) (int)x.size()
  33. #define ss second
  34. #define sRand srand(chrono::steady_clock::now().time_since_epoch().count())
  35. #define timeTaken endd = clock(); cout << (double) (endd - beginn) / CLOCKS_PER_SEC * 1000 << endl
  36. #define timeInit clock_t beginn = clock(), endd
  37. #define ull unsigned long long
  38. #define umsi unordered_map<string, int>
  39. #define umii unordered_map<int, int>
  40. #define umis unordered_map<int, string>
  41. #define vb vector<bool>
  42. #define vi vector<int>
  43. #define vvi vector<vi>
  44. #define vii vector<pii>
  45. #define vvii vector<vii>
  46. #define vll vector<ll>
  47. #define vvll vector<vll>
  48. #define vpll vector<pll>
  49. #define bug(...) cerr << __PRETTY_FUNCTION__ << " - " << __LINE__ << " : (" << #__VA_ARGS__ << ") = ("; _Print(__VA_ARGS__);
  50. template<class T> void _Print(T &&x) { cerr << x << ")" << endl; }
  51. template<class T, class ...S> void _Print(T &&x, S &&...y) { cerr << x << ", "; _Print(y...); }
  52.  
  53. /*
  54. #include <ext/pb_ds/assoc_container.hpp>
  55. #include <ext/pb_ds/tree_policy.hpp>
  56. #include <functional>
  57. using namespace __gnu_pbds;
  58. typedef tree<int,null_type, less<int>, rb_tree_tag,
  59. tree_order_statistics_node_update> ordered_set;
  60.  
  61. //os.order_of_key(v): returns how many elements strictly less than v
  62. //os.find_by_order(k - 1): returns kth smallest element's iterator
  63. */
  64.  
  65. template<class T> class compare {
  66. public:
  67. bool operator() (pair<T, T> &x, pair<T, T> &y) {
  68. if (x.first == y.first) {
  69. return x.ss > y.ss;
  70. }
  71. return x.ff > y.ff;
  72. }
  73. };
  74.  
  75. template<class T> ostream &operator<<(ostream &os, const pair<T, T> &a) { return os << a.ff << " " << a.ss; }
  76. ll power(ll a, int b) {
  77. ll po = 1;
  78. while (b) {
  79. if (b & 1)
  80. po *= a;
  81. a *= a;
  82. b >>= 1;
  83. }
  84. return po;
  85. }
  86.  
  87. template<class T> pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return {a.ff + b.ff, a.ss + b.ss}; }
  88. template<class T> pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return {a.ff - b.ff, a.ss - b.ss}; }
  89. template<class T> pair<T, T> operator*(const pair<T, T> &a, const pair<T, T> &b) { return {a.ff * b.ff, a.ss * b.ss}; }
  90. template<class T> pair<T, T> operator%(const pair<T, T> &a, const pair<T, T> &b) { return {a.ff % b.ff, a.ss % b.ss}; }
  91. template<class T, class U> pair<T, T> operator+(const pair<T, T> &a, const U &b) { return {a.ff + b, a.ss + b}; }
  92. template<class T, class U> pair<T, T> operator*(const pair<T, T> &a, const U &b) { return {a.ff * b, a.ss * b}; }
  93.  
  94. ll Set(ll N, int pos) { return N = N | (1LL << pos); }
  95. int reset(int N, int pos){ return N = N & ~ (1 << pos); }
  96. bool check(ll N, int pos){ return (bool) (N & (1LL << pos)); }
  97.  
  98. ///=======================================template=======================================///
  99.  
  100. int main() {
  101. //FI;FO;
  102. FastIO;//timeInit;
  103.  
  104. int t;
  105. cin >> t;
  106. for (int tc = 1; tc <= t; tc++) {
  107. cout << "Case " << tc << ":" << endl;
  108. int n;
  109. cin >> n;
  110. vvi g(n);
  111. char mat[n][n];
  112. for (int i = 0; i < n; i++) {
  113. for (int j = 0; j < n; j++) {
  114. int x;
  115. cin >> x;
  116. if (x)
  117. g[i].pb(j);
  118. }
  119. }
  120.  
  121. vi vis(n, false);
  122.  
  123. queue<int> q;
  124. q.push(0);
  125.  
  126. while (!q.empty()) {
  127. int u = q.front();
  128. vis[u] = true;
  129. q.pop();
  130. for (auto &v : g[u]) {
  131. if (!vis[v])
  132. q.push(v);
  133. }
  134. }
  135.  
  136. for (int i = 0; i < n; i++) {
  137. if(vis[i])
  138. mat[0][i] = 'Y';
  139. else mat[0][i] = 'N';
  140. }
  141.  
  142. for (int i = 1; i < n; i++) {
  143. while (!q.empty())
  144. q.pop();
  145. q.push(0);
  146.  
  147. vi viss(n, false);
  148. while(!q.empty()) {
  149. int u = q.front();
  150. q.pop();
  151. viss[u] = true;
  152.  
  153. for (auto &v : g[u]) {
  154. if (v == i)
  155. continue;
  156. else if (!viss[v])
  157. q.push(v);
  158. }
  159. }
  160.  
  161. for (int j = 0; j < n; j++) {
  162. if (vis[j] and !viss[j]) {
  163. mat[i][j] = 'Y';
  164. }
  165. else mat[i][j] = 'N';
  166. }
  167. }
  168.  
  169. string form;
  170. form += "+";
  171. for (int i = 0; i < 2 * n - 1; i++)
  172. form += '-';
  173. form += "+";
  174. for (int i = 0; i < n; i++) {
  175. cout << form << endl;
  176. for (int j = 0; j < n; j++) {
  177. cout << "|" << mat[i][j];
  178. }
  179. cout << "|" << endl;
  180. }
  181. cout << form << endl;
  182. }
  183.  
  184. //timeTaken;
  185. return 0;
  186. }
Advertisement
Add Comment
Please, Sign In to add comment