zoukankan      html  css  js  c++  java
  • 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         else
    61             puts( "No" );
    62         for( int i = 1; i <= n; ++i )
    63             nod[i].clear();
    64     }
    65     return 0;
    66 }
  • 相关阅读:
    小Z的袜子
    C#操作XML
    C#中接口的实现方法
    C#邮箱批量注册
    C# 委托的使用
    C# socket
    在C#.net中如何操作XML
    C#接口的基础知识
    C#判断网页中是否含有某字符串
    C#多线程处理多个队列的数据
  • 原文地址:https://www.cnblogs.com/ADAN1024225605/p/4109146.html
Copyright © 2011-2022 走看看