Metal Steak

Hard to eat

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

公告

aaaaaaaaaaaa

常用链接

留言簿(1)

我参与的团队

搜索

  •  

最新评论

#include <iostream>
using namespace std;

int    info[101][101];
int    n;
int    ans[101], ap;

struct
node
{
    
int    ind;
    
int    outd;
    node()
    {
        ind 
=
        outd 
= 0;
    }
}soldier[
101];

void
__read__()
{
    cin 
>> n;
    
forint i = 1; i <= n; i++ )
    {
        
int x, y;
        cin 
>> x >> y;
        info[x][y] 
= true;    // x is taller than y.
        soldier[x].outd++;
        soldier[y].ind
++;
    }
}

int
find_to_del()
{
    
forint i = 1; i <= n; i++ )
        
if( soldier[i].ind == 0 )
            
return i;
    
return -1;
}

void
__topo__()
{
    
int to_del = 0;
    
while( ( to_del = find_to_del() ) != -1 )
    {
        
forint i = 1; i <= n; i++ )
            
if( info[to_del][i] )
            {
                info[to_del][i] 
= false;
                soldier[i].ind
--;
            }
        soldier[to_del].ind 
= -1;
        ans[
++ap] = to_del;
        to_del 
= 0;
    }
}

void
__outp__()
{
    
forint i = 1; i <= n; i++ )
        cout 
<< ans[i] << " ";
    cout 
<< endl;
}

int
main()
{
    __read__();
    __topo__();
    __outp__();

    
return 0;
}

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

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