Lang:G++
Edit12345678910111213141516171819202122232425262728293031#include <iostream>#include <vector>#include <map>#include <list>#include <memory>#include <cstring>using namespace std;vector< vector<int> > tree;vector< vector< pair<int,int> > > section;vector<int> height;void dfs(int root){if(tree[root].empty()) return;int sectionStart = 0;int tempSection = 0;for(int i = 0;i<section[root].size(); i++){int num = section[root][i].first;int j = 0;while(num--){int child = tree[root][sectionStart + j];//cout<<child<<',';dfs(child);section[root][i].second=max(section[root][i].second, max(section[root][i].first,height[child]+j));j++;}sectionStart += j;height[root] = min(max(height[root]+section[root][i].first,section[root][i].second),max(height[root],section[root][i].second+tempSection));tempSection += section[root][i].first;//cout<<root<<",i="<<i<<",height[root]="<<height[root]<<",s[i]="<<section[root][i].first<<",h[i]"<<section[root][i].second<<endl;