#P1118F1. Tree Cutting (Easy Version)
Tree Cutting (Easy Version)
No submission language available for this problem.
Description
You are given an undirected tree of vertices.
Some vertices are colored blue, some are colored red and some are uncolored. It is guaranteed that the tree contains at least one red vertex and at least one blue vertex.
You choose an edge and remove it from the tree. Tree falls apart into two connected components. Let's call an edge nice if neither of the resulting components contain vertices of both red and blue colors.
How many nice edges are there in the given tree?
The first line contains a single integer () — the number of vertices in the tree.
The second line contains integers () — the colors of the vertices. means that vertex is colored red, means that vertex is colored blue and means that vertex is uncolored.
The -th of the next lines contains two integers and (, ) — the edges of the tree. It is guaranteed that the given edges form a tree. It is guaranteed that the tree contains at least one red vertex and at least one blue vertex.
Print a single integer — the number of nice edges in the given tree.
Input
The first line contains a single integer () — the number of vertices in the tree.
The second line contains integers () — the colors of the vertices. means that vertex is colored red, means that vertex is colored blue and means that vertex is uncolored.
The -th of the next lines contains two integers and (, ) — the edges of the tree. It is guaranteed that the given edges form a tree. It is guaranteed that the tree contains at least one red vertex and at least one blue vertex.
Output
Print a single integer — the number of nice edges in the given tree.
Samples
Note
Here is the tree from the first example:

The only nice edge is edge . Removing it makes the tree fall apart into components and . The first component only includes a red vertex and the second component includes blue vertices and uncolored vertices.
Here is the tree from the second example:

Every edge is nice in it.
Here is the tree from the third example:

Edge splits the into components and , the latter one includes both red and blue vertex, thus the edge isn't nice. Edge splits the into components and , the former one includes both red and blue vertex, thus the edge also isn't nice. So the answer is 0.