using
System;
using
System.Collections.Generic;
class
Node
{
public
char
Key {
get
;
set
; }
public
List<Node> Children {
get
;
set
; }
public
Node(
char
key)
{
Key = key;
Children =
new
List<Node>();
}
}
class
Program
{
static
int
Factorial(
int
n)
{
if
(n == 0)
{
return
1;
}
return
n * Factorial(n - 1);
}
static
int
CalculateWays(Node root)
{
int
ways = 1;
if
(root ==
null
)
{
return
0;
}
Queue<Node> queue =
new
Queue<Node>();
queue.Enqueue(root);
while
(queue.Count != 0)
{
Node current = queue.Dequeue();
ways *= Factorial(current.Children.Count);
foreach
(Node child
in
current.Children)
{
queue.Enqueue(child);
}
}
return
ways;
}
static
void
Main(
string
[] args)
{
Node root =
new
Node(
'A'
);
root.Children.Add(
new
Node(
'B'
));
root.Children.Add(
new
Node(
'F'
));
root.Children.Add(
new
Node(
'D'
));
root.Children.Add(
new
Node(
'E'
));
root.Children[0].Children.Add(
new
Node(
'K'
));
root.Children[0].Children.Add(
new
Node(
'J'
));
root.Children[2].Children.Add(
new
Node(
'G'
));
root.Children[3].Children.Add(
new
Node(
'C'
));
root.Children[3].Children.Add(
new
Node(
'H'
));
root.Children[3].Children.Add(
new
Node(
'I'
));
root.Children[0].Children[0].Children.Add(
new
Node(
'N'
));
root.Children[0].Children[0].Children.Add(
new
Node(
'M'
));
root.Children[3].Children[2].Children.Add(
new
Node(
'L'
));
Console.WriteLine(CalculateWays(root));
}
}