Sort by

recency

|

73 Discussions

|

  • + 0 comments

    DFS on subset tree

    class disjoint_set {
    public:
        vector<int> parent, size;
        disjoint_set(int n) {
            parent.resize(n);
            iota(parent.begin(), parent.end(), 0);
            size.resize(n, 1);
        }
        int find(int x) {
            if (x != parent[x]) parent[x] = find(parent[x]);
            return parent[x];
        }
        bool Union(int x, int y) {
            int xRep = find(x), yRep = find(y);
            if (xRep == yRep) return false;
            if (size[xRep] <= size[yRep]) {
                parent[xRep] = yRep;
                size[yRep] = size[yRep] + size[xRep];
            }
            else {
                parent[yRep] = xRep;
                size[xRep] = size[xRep] + size[yRep];
            }
            return true;
        }
    };
    
    void travel(const vector<long>& D, vector<bool> subset, disjoint_set partition, int level, int components, int& total, long nodeSet) {
        int newComponents = components;
        if (subset[level] == true) {
            nodeSet = nodeSet | D[level];
            ++newComponents;
            for (int i=0; i <= level; ++i) {
                if (subset[i] and (D[i] & D[level]) != 0 and partition.Union(i, level) == true) {
                    --newComponents;
                }
            }
            total = total + 64 - __builtin_popcountl(nodeSet) + newComponents;
        }
        if (level == D.size() - 1) return;
        travel(D, subset, partition, level + 1, newComponents, total, nodeSet);
        subset[level + 1] = true;
        travel(D, subset, partition, level + 1, newComponents, total, nodeSet);
    }
    
    
    int findConnectedComponents(int N, const vector<long>& D) {
        int total = 64;
        vector<bool> subset(N);
        disjoint_set partition(N);
        travel(D, subset, partition, 0, 0, total, 0);
        subset[0] = true;
        travel(D, subset, partition, 0, 0, total, 0);
        return total;   
    }
    
  • + 0 comments

    Locksmith Barnsley offers expert services for any security needs! If you’re working on a subset component of your home or business security system, their team provides reliable solutions. Whether you need to upgrade your locks, replace a key, or fix a faulty system, they’re equipped to help. Count on their experienced professionals to ensure your security is top-notch, giving you peace of mind with high-quality locksmith services in Barnsley.

  • + 0 comments

    Why the fxxk is result for the input [0] or any element with 1 set bit NOT 64!?! My understanding of the problem definition is that there is 64 singletons as "connected" components in a number with a single set bit!?!

  • + 0 comments

    Branded notepads can be an excellent tool for organizing and noting down key details about any project, including a subset component. Whether you're analyzing the smaller parts that make up a larger system or mapping out individual elements, these notepads help you stay organized. Customizing them with your brand adds a professional touch, ensuring your message is always front and center while staying functional for your team or clients.

  • + 0 comments

    The quality of the problems is good, but the platform's UI and the phrasing of the problems are quite irritating.