924. Minimize Malware Spread

方法一:并查集

class Solution {
public:
    int parents[301];
    int col[301];
    int findparent(int x){
        int p = x,temp = x;
        while(p!=parents[p]){
           p = parents[p];
        }
        while(temp != p){
            int j = parents[temp];
            parents[temp] = p;
            temp = j;
        }
        return parents[x];
    }
    void unit(int x,int y){
        int px = findparent(x);
        int py = findparent(y);
        if(px>& graph, vector& initial) {
        int len = graph.size();
        for(int i =0;imaxcol)
            {
                maxcol = col[findparent(index)];
                maxindex = index;
            }
        }
        return maxindex;
    }
};

方法二:BFS

class Solution {
public:
    int minMalwareSpread(vector>& graph, vector& initial) {
        sort(initial.begin(),initial.end());
        vector nodes(graph.size(),1);
        vector temp;
        queue stacks;
        int maxv = INT_MIN;
        int maxi = INT_MIN;
        for(int i =0;i maxv) {
                    maxv = temp.size();
                    maxi = initial[i];
                }
            }
        }
        return maxi;
    }
};

问题:
奇怪,如果直接temp.size()>maxv,输出为INT_MIN,想不明白

你可能感兴趣的:(924. Minimize Malware Spread)