/*
x
a b c
x无关
x有关
*/
#include <iostream>
#include <vector>
using namespace std;
struct staff
{
int happy;
vector<staff> subs;
staff(int h)
{
happy = h;
}
};
struct info
{
int laimaxhappy;
int bulaimaxhappy;
info(int lai, int bulai)
{
laimaxhappy = lai;
bulaimaxhappy = bulai;
}
};
info process(staff* s)
{
int lai = s->happy;
int bulai = 0;
if(s->subs.size() == 0)
{
return info(s->happy, 0);
}
else
{
for(staff it : s->subs)
{
info subinfo = process(&it);
lai += subinfo.bulaimaxhappy;
bulai += max(subinfo.laimaxhappy, subinfo.bulaimaxhappy);
}
return info(lai, bulai);
}
}
int getMax(staff* boss)
{
info treeInfo = process(boss);
return max(treeInfo.laimaxhappy, treeInfo.bulaimaxhappy);
}
int main()
{
staff s1(1);
staff s2(2);
staff s3(3);
staff s4(4);
staff s5(5);
vector<staff> v;
v.push_back(s1);
v.push_back(s2);
v.push_back(s3);
v.push_back(s4);
v.push_back(s5);
vector<staff> v1sub;
v1sub.push_back(s2);
v1sub.push_back(s3);
s1.subs = v1sub;
vector<staff> v2sub;
v2sub.push_back(s4);
s2.subs = v2sub;///期望s2.subs这个vector里有一个s4,可是debug发现没有
vector<staff> v3sub;
v3sub.push_back(s5);
s3.subs = v3sub;///期望s3.subs这个vector里有一个s5,可是debug发现没有
cout << getMax(&s1) << endl;
}