Metal Steak

Hard to eat

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

公告

aaaaaaaaaaaa

常用链接

留言簿(1)

我参与的团队

搜索

  •  

最新评论

#include <iostream>
using namespace std;

int
n, _root_, depth, width[
501= {0}, tmp[501][501= {0};

void
__readandinit__();
void
__solve__(
int _fath_, int level);
int
getMaxOfArray(
int n, int *array);

int
main()
{
    __readandinit__();
    __solve__(_root_, 
1);

    cout 
<< depth << " " << getMaxOfArray(n, width) << endl;

    
return 0;
}

void
__readandinit__()
{
    cin 
>> n;
    
for(int i = 1; i <= n; i++)
    {
        
int x, y;
        cin 
>> x >> y;
        tmp[x][y] 
= true;
        
if(y == 0)
        _root_ 
= x;
    }
}

void
__solve__(
int _fath_, int level)
{
    width[level]
++;
    
int leaf = true;
    
for(int i = 1; i <= n; i++)
        
if(tmp[i][_fath_])
        {
            leaf 
= false;
            __solve__(i, level 
+ 1);
        }
    
if(leaf)
        
if(level >= depth)
            depth 
= level;
}

int getMaxOfArray(int n, int *array)
{
    
int m = array[1];
    
for(int i = 1; i <= n; i++)
        
if(array[i] > m)
            m 
= array[i];

    
return m;
}

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

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