Metal Steak

Hard to eat

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

公告

aaaaaaaaaaaa

常用链接

留言簿(1)

我参与的团队

搜索

  •  

最新评论

#include <iostream>
using namespace std;

int
father[
101], x, y, recordf[101], ancestor;

void
__read__()
{
    cin 
>> x >> y;
    
int
    a, b;
    
while( cin >> a >> b )
        father[a] 
= b;
}

void
__ca__()
{
    
int f = x;
    
while( f )
    {
        recordf[f] 
= true;
        f 
= father[f];
    }
    f 
= y;
    
while!recordf[f] )
        f 
= father[f];
    ancestor 
= f;
}

void
__erg1__( 
int q )
{
    
if( q != ancestor )
    {
        cout 
<< q << " ";
        __erg1__( father[q] );
    }
    
if( q == ancestor )
        cout 
<< q << " ";
}

void
__erg2__( 
int p )
{
    
if( p != ancestor )
    {
        __erg2__( father[p] );
        cout 
<< p << " ";
    }
}

int
main()
{
    __read__();
    __ca__();
    __erg1__( x );
    __erg2__( y );
    cout 
<< endl;

    
return 0;
}

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

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