首页 > 代码库 > HDU1269

HDU1269

 判断强联通图

 

 1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <cmath> 5 #include <cctype> 6 #include <time.h> 7 #include <string> 8 #include <set> 9 #include <map>10 #include <queue>11 #include <vector>12 #include <stack>13 #include <algorithm>14 #include <iostream>15 using namespace std;16 #define PI acos( -1.0 )17 typedef long long ll;18 typedef pair<int,int> P;19 const double E = 1e-8;20 21 const int NO = 10000 +5;22 vector <int> nod[NO];23 int mark[NO];24 int n, m;25 26 void dfs( int x )27 {28     mark[x] = 1;29     for( int i = 0; i < nod[x].size(); ++i )30         if( !mark[nod[x][i]] )31             dfs( nod[x][i] );32 }33 34 int main()35 {36     while( ~scanf( "%d%d", &n, &m ) && n+m )37     {38         int x, y;39         while( m-- )40         {41             scanf( "%d%d", &x, &y );42             nod[x].push_back( y );43         }44         bool flag = true;45         for( int i = 1; i <= n; ++i )46         {47             memset( mark, 0, sizeof( mark ) );48             dfs( i );49             for( int j = 1; j <= n; ++j )50                 if( !mark[j] )51                 {52                     flag = false;53                     break;54                 }55             if( !flag )56                 break;57         }58         if( flag )59             puts( "Yes" );60         else61             puts( "No" );62         for( int i = 1; i <= n; ++i )63             nod[i].clear();64     }65     return 0;66 }

 

HDU1269