[leetcode] 1192 critical-connections-in-a-network

https://leetcode.com/contest/weekly-contest-154/problems/critical-connections-in-a-network/

class Solution {
 public : 
    Vector <Vector < int >> RES;
     int index = 0 ; // access number 
    Vector < int > DFN; // number of the current access 
    Vector < int > Low; // current node & earliest its subtree the serial access 

    Vector <Vector < int >> Graph;
     void Tarjan ( int CUR, int Last) 
    { 
        Low [CUR] = DFN [CUR] = index ++; // allocate a sequence number 
        for ( const& Auto Next: Graph [CUR]) 
        { 
            IF (== Next Last) Continue ; // to avoid visiting the          
            IF (DFN [Next] == - . 1 ) 
            { 
                Tarjan (Next, CUR);   // not visited, the search continues 
                low [CUR] = min (low [CUR], low [Next]); // update the first ID 
                IF (low [Next]> DFN [CUR]) // new node is low is greater than the number of the current node have been described not have a strong link with the component in the 
                { 
                    res.push_back ({CUR, Next}); // added to the result 
                } 
            } 
            the else  
            {
                Low [CUR]= min(low[cur], dfn[next]);// 访问过了,直接更新
                //low[cur] = min(low[cur], low[next]);  -> I think this is right !
            }
        }
    }

    vector<vector<int>> criticalConnections(int n, vector<vector<int>>& connections) {
        dfn.resize(n, -1);
        low.resize(n, -1);    
        graph.resize(n);
        for (int i = 0; i < connections.size(); i++)
        {
            Vector <int> C = & Connections [I];
             int V1 = C [ 0 ];
             int V2 = C [ . 1 ]; 
            Graph [V1] .push_back (V2); 
            Graph [V2] .push_back (V1); 
        } 
        Tarjan ( 0 , - . 1 ); // in a strong link with the node components, result in the same low value of
       //   for (int I = 0; I <n-; I ++) << low COUT [I] << "" < <DFN [I] << endl; 
        return RES; 
    } 
};

 

Guess you like

Origin www.cnblogs.com/fish1996/p/11522072.html
Recommended