using System;
using System.Collections.Generic;
class GFG
{
public class Node
{
public int key;
public List<Node> child = new List<Node>();
public Node(int data)
{
key = data;
}
};
static int numberOfChildren(Node root, int x)
{
int numChildren = 0;
if (root == null)
return 0;
Queue<Node> q = new Queue<Node>();
q.Enqueue(root);
while (q.Count != 0)
{
int n = q.Count;
while (n > 0)
{
Node p = q.Peek();
q.Dequeue();
if (p.key == x)
{
numChildren = numChildren +
p.child.Count;
return numChildren;
}
for (int i = 0; i < p.child.Count; i++)
q.Enqueue(p.child[i]);
n--;
}
}
return numChildren;
}
public static void Main(String[] args)
{
Node root = new Node(20);
(root.child).Add(new Node(2));
(root.child).Add(new Node(34));
(root.child).Add(new Node(50));
(root.child).Add(new Node(60));
(root.child).Add(new Node(70));
(root.child[0].child).Add(new Node(15));
(root.child[0].child).Add(new Node(20));
(root.child[1].child).Add(new Node(30));
(root.child[2].child).Add(new Node(40));
(root.child[2].child).Add(new Node(100));
(root.child[2].child).Add(new Node(20));
(root.child[0].child[1].child).Add(new Node(25));
(root.child[0].child[1].child).Add(new Node(50));
int x = 50;
Console.WriteLine(numberOfChildren(root, x));
}
}