Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define ll long long
- #include <bits/stdc++.h>
- using namespace std;
- const int OO = 1e9;
- const double EPS = 1e-9;
- class BobTrouble {
- public:
- queue<int> q;
- bool done[51];
- bool in_q[51];
- bool is_supervisor[51];
- int minSupers(vector <string> name, vector <string> bossName) {
- memset(done,0,sizeof(done));
- memset(is_supervisor,0,sizeof(is_supervisor));
- memset(in_q,0,sizeof(in_q));
- while(!q.empty())
- q.pop();
- for(int i = 0; i < name.size(); i++) {
- if(bossName[i] == "*") {
- q.push(i);
- in_q[i] = 1;
- }
- }
- while(!q.empty()) {
- int curr = q.front();
- q.pop();
- if(!done[curr]) {
- done[curr] = 1;
- for(int i = 0; i < name.size(); i++) {
- if(i != curr && !in_q[i] && bossName[i] == name[curr]) {
- q.push(i);
- in_q[i] = 1;
- is_supervisor[curr] = 1;
- }
- }
- }
- }
- int ans = 0;
- for(int i = 0; i < name.size(); i++) {
- if(!done[i]) {
- ans = -1;
- break;
- }
- ans += is_supervisor[i];
- }
- return ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement