Metal Steak

Hard to eat

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  0 Posts :: 79 Stories :: 0 Comments :: 0 Trackbacks

公告

aaaaaaaaaaaa

常用链接

留言簿(1)

我参与的团队

搜索

  •  

最新评论

#include <iostream>
using namespace std;

int
main()
{
    
int    n, m;
    
int    vst[101= { 0 };
    
int    que[101= { 0 };
    
int    f = 1, r = 0;
    
int    map[101][101= { { 0 } };

    cin 
>> n >> m;
    
forint i = 1; i <= m; i++ )
    {
        
int x, y;
        cin 
>> x >> y;
        map[x][y] 
=
        map[y][x] 
= true;
    }

    
forint i = 1; i <= n; i++ )
        
if!vst[i] )
        {
            que[
++r] = i;
            vst[que[f]] 
= true;
            
while1 )
            {
                
forint i = 1; i <= n; i++ )
                    
if!vst[i] && map[que[f]][i] )
                    {
                        vst[i] 
= true;
                        que[
++r] = i;
                    }
                f
++;
                
if( f == r + 1 )
                    
break;
            }
        }
    
forint i = 1; i <= n; i++ )
        cout 
<< que[i] << " ";
    cout 
<< endl;

    
return 0;
}

posted on 2009-09-15 21:44 mad4alcohol 阅读(114) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航:   博客园   博客园最新博文   博问   管理