我自己能想到的测试数据基本都试过了,没问题,但提交全是WA
#include <iostream>
#include <map>
using namespace std;
int main()
{
int n = 0;
cin >> n;
int maxNum = 0;
map<int, int> mp;
mp[1] = 1;
for (int i = 1; i <= n; ++i)
{
int l = 0;
int r = 0;
cin >> l >> r;
int idx = mp[i];
if (idx != 0)
{
if (l != 0)
{
maxNum = 2 * idx;
mp[l] = idx * 2;
}
if (r != 0)
{
maxNum = 2 * idx + 1;
mp[r] = idx * 2 + 1;
}
}
}
int h = 0;
do
{
maxNum /= 2;
++h;
} while (maxNum != 0);
cout << h << endl;
}