finding bridges

Правка en1, от ChemliYoussef, 2016-08-03 22:40:10

Hi everyone ... I don't why my BridgeFinding code gives a wrong anwser for graph : 6 7 -- > n , m 1 2 -- > edge : u -- v 2 3 1 3 3 4 4 6 4 6 4 5 The problem that i don't know why it takes edge-s 4 -- 6 as a bridge code :

#include<bits/stdc++.h>

#define read_fast ios_base::sync_with_stdio(0) , cin.tie(0)
#define ll long long int 
#define pb push_back
#define mp make_pair

using namespace std ;

int n , m , dfs_Count ;
int dfs_num [ 1010 ] , dfs_low [ 1010 ] , dfs_par [ 1010 ] ;
vector < int  > adj [ 1010 ] ; 

void Bridge ( int u ) 
{
    dfs_low [ u ] = dfs_num [ u ] = ++ dfs_Count ; 
    for ( int i = 0 ; i < adj [ u ] . size() ; i ++ )
    {
        int j = adj [ u ][ i ]  ; 
        if ( ! dfs_num [ j ] )
        {
            dfs_par [ j ] = u ;
            
            Bridge ( j ) ;
            
            if ( dfs_low [ j ] > dfs_num [ u ] )
            { 
                cout << u << " " << j << '\n' ; 
            }
            dfs_low [ u ] = min ( dfs_low [ u ] , dfs_low [ j ] ) ;
        }
        else if ( j != dfs_par [ u ] )
            dfs_low [ u ] = min ( dfs_low [ u ] , dfs_num [ j ] ) ;
    }
    
    return ;
}

int main()
{
    read_fast ;
    
    cin >> n >> m ;
    for ( int i = 0 ; i < m ; i ++ )
    { 
        int a , b ;
        cin >> a >> b ;
        adj [ a ] . pb ( b ) ;
        adj [ b ] . pb ( a ) ;
    }
    
    Bridge ( 1 ) ;
    
    return 0 ;
}

Thanks in advance

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en4 Английский ChemliYoussef 2016-08-03 22:44:58 3 Tiny change: 'takes edge-s 4 -- 6 as' -> 'takes edge 4 -- 6 as'
en3 Английский ChemliYoussef 2016-08-03 22:44:30 70
en2 Английский ChemliYoussef 2016-08-03 22:41:16 20
en1 Английский ChemliYoussef 2016-08-03 22:40:10 1581 Initial revision (published)