Advertisement
_rashed

SRM292-D1-500

Feb 21st, 2022
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. #define ll long long
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. const int OO = 1e9;
  6. const double EPS = 1e-9;
  7.  
  8. class BobTrouble {
  9. public:
  10.     queue<int> q;
  11.     bool done[51];
  12.     bool in_q[51];
  13.     bool is_supervisor[51];
  14.     int minSupers(vector <string> name, vector <string> bossName) {
  15.         memset(done,0,sizeof(done));
  16.         memset(is_supervisor,0,sizeof(is_supervisor));
  17.         memset(in_q,0,sizeof(in_q));
  18.         while(!q.empty())
  19.             q.pop();
  20.         for(int i = 0; i < name.size(); i++) {
  21.             if(bossName[i] == "*") {
  22.                 q.push(i);
  23.                 in_q[i] = 1;
  24.             }
  25.         }
  26.         while(!q.empty()) {
  27.             int curr = q.front();
  28.             q.pop();
  29.             if(!done[curr]) {
  30.                 done[curr] = 1;
  31.                 for(int i = 0; i < name.size(); i++) {
  32.                     if(i != curr && !in_q[i] && bossName[i] == name[curr]) {
  33.                         q.push(i);
  34.                         in_q[i] = 1;
  35.                         is_supervisor[curr] = 1;
  36.                     }
  37.                 }
  38.             }
  39.         }
  40.         int ans = 0;
  41.         for(int i = 0; i < name.size(); i++) {
  42.             if(!done[i]) {
  43.                 ans = -1;
  44.                 break;
  45.             }
  46.             ans += is_supervisor[i];
  47.         }
  48.         return ans;
  49.     }
  50. };
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement