Advertisement
NonWhite

grafos

Jul 17th, 2012
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <string>
  4. #include <cstring>
  5. #include <vector>
  6. #define TAM 110
  7.  
  8. using namespace std;
  9.  
  10. vector<int> g[ TAM ] ;
  11. bool v[ TAM ] ;
  12. vector<int> tp ;
  13.  
  14. void init(){
  15.     for(int i = 0 ; i < TAM ; i++) g[ i ] .clear() ;
  16.     memset( v, 0 , sizeof v ) ;
  17.     tp.clear() ;
  18. }
  19.  
  20. void dfs( int x ){
  21.     v[ x ] = true ;
  22.     for(int i = 0 ; i < g[ x ] .size() ; i++){
  23.         int u = g[ x ][ i ] ;
  24.         if( v[ u ] ) continue ;
  25.         dfs( u ) ;
  26.     }
  27.     tp.push_back( x+1 ) ;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement