趁机求大神们指导,我的40%然后就告诉我运行出错了,怎么看都看不出哪错了啊T-T.......
int main()
{
    int num;
    int pre[1000] = {0};
    int height[1000] = {0};

    cin >> num;
    num--;
    int parent, child;
    int max_height = 0;
    for(int i = 0; i < 1000; i++)
        pre[i] = i;
    while(num--)
    {
        cin >> parent >> child;
        pre[child] = parent;

        if(height[child] + 1 > height[parent])
            height[parent] = height[child] + 1;
        while(pre[parent] != parent)
        {
            height[pre[parent]] = height[parent] + 1;
            parent = pre[parent];
        }
        if(height[parent] > max_height)
            max_height = height[parent];
    }
    cout << max_height + 1 << endl;
    return 0;
}