#include <bits/stdc++.h>
using
namespace
std;
class
Node {
public
:
vector<Node*> children;
int
val;
Node(
int
v)
{
val = v;
children = {};
}
};
int
postOrder(Node* root,
int
maxi[])
{
if
(root->children.size() == 0)
return
1;
int
sum = 1;
for
(Node* child : root->children) {
int
nodes = postOrder(child, maxi);
if
(child->val == root->val)
sum += nodes;
}
maxi[0] = max(maxi[0], sum);
return
sum;
}
int
largestGroup(Node* root)
{
if
(root == NULL)
return
0;
int
maxi[1];
postOrder(root, maxi);
return
maxi[0];
}
int
main()
{
Node* three1 =
new
Node(3);
Node* three2 =
new
Node(3);
Node* three3 =
new
Node(3);
Node* three4 =
new
Node(3);
Node* two1 =
new
Node(2);
Node* two2 =
new
Node(2);
Node* two3 =
new
Node(2);
Node* two4 =
new
Node(2);
Node* four1 =
new
Node(4);
Node* four2 =
new
Node(4);
Node* four3 =
new
Node(4);
Node* one1 =
new
Node(1);
Node* one2 =
new
Node(1);
Node* one3 =
new
Node(1);
Node* one4 =
new
Node(1);
three2->children.push_back(two1);
three2->children.push_back(three1);
three2->children.push_back(three3);
four1->children.push_back(four2);
four1->children.push_back(four3);
two2->children.push_back(one1);
two2->children.push_back(one2);
two2->children.push_back(two3);
one3->children.push_back(one4);
one3->children.push_back(two4);
three4->children.push_back(three2);
three4->children.push_back(four1);
three4->children.push_back(two2);
three4->children.push_back(one3);
cout << (largestGroup(three4));
}