[c++] bitset & union find [50ms]
This problem is the perfect one to use bitset. since # is less than 1000.\nwe have 2 bitset array \nvector<bitset<1000>> hate;\nvector<bitset<1000>> g;\nreprese
This problem is the perfect one to use bitset. since # is less than 1000.\nwe have 2 bitset array \nvector<bitset<1000>> hate;\nvector<bitset<1000>> g;\nrepresent a group\'s member, and a group\'s members\'s hate-list(can not be friend with).\n\n```\nclass Solution {\npublic:\n    vector<int> parent;\n    vector<bitset<1000>> hate;\n    vector<bitset<1000>> g;\n    int findp(int p) {\n        return (parent[p] == p) ? p : parent[p]=findp(parent[p]);\n    }\n    bool tryun(int a, int b) {\n        int pa = findp(a);\n        int pb = findp(b);\n        if (pa == pb) return true;\n        if ((hate[pa] & g[pb]).any()) return false;\n        g[pa] |= g[pb];\n        hate[pa] |= hate[pb];\n        parent[pb] = pa;\n        return true;\n    }\n    vector<bool> friendRequests(int n, vector<vector<int>>& restrictions, vector<vector<int>>& requests) {\n        parent.resize(n);\n        hate.resize(n);\n        g.resize(n);\n        for (int i = 0; i < n; i++) { parent[i] = i; g[i][i] = 1;} \n        for (auto& r : restrictions)  { hate[r[0]][r[1]] = 1; hate[r[1]][r[0]] = 1;}\n        vector<bool> ans;\n        for (auto& r : requests) ans.push_back(tryun(r[0], r[1]));\n        return ans;\n    }\n};\n```
[]