This page is still under construction.

Parts of this page are still being built. What you see may change.

Tree Coloring

Time limit1sMemory limit512 MB

Summary
Given a rooted tree and a target color for each vertex, count the fewest subtree-recoloring operations (colors other than white) that reach the target.
Level

Medium7 of 10

Topics
Tree, DFS, Greedy, Implementation
Solved
No attempts yet

Problem

There is a tree with NN vertices. The vertices are numbered from 1 to NN. The root of the tree is always vertex 1, and initially every vertex is colored white.

Coloring a vertex colors every vertex in its subtree with the same color. Colors do not blend; each coloring overwrites the previous one with the new color. White cannot be used for coloring.

Suppose there is a tree with 10 vertices, as in the figure below.

[Figure 1] A tree colored white

If vertex 3 is colored yellow, then vertices 5, 6, 8, 9, and 10 below it all become yellow.

[Figure 2] The tree after coloring vertex 3 yellow

Then, if vertex 5 is colored blue, then vertices 8, 9, and 10 below it all become blue.

[Figure 3] The tree after coloring vertex 5 blue

The input gives the tree and the color of each vertex. A color is given as a nonnegative integer, and the value 0 always means white.

Using only colors other than white, find the minimum number of colorings needed to color every vertex with its given color.

Input

The first line gives the number of vertices in the tree, N(1≤N≤200,000)N(1 ≤ N ≤ 200,000).

The second line gives the color Ci(0≤Ci≤N)C_i (0 ≤ C_i ≤ N) of each vertex from vertex 1 to vertex NN, separated by spaces.

Each of the next N−1N - 1 lines gives two connected vertices a,b(1≤a,b≤Na, b(1 ≤ a, b ≤ N, a≠b)a ≠ b), separated by spaces.

Only inputs for which every vertex can be colored are given.

Output

Print the minimum number of colorings needed to color every vertex with its desired color using only colors other than white.

Examples2

  1. Example 1

    Input
    7
    0 0 2 0 1 2 2
    1 2
    1 3
    1 4
    2 5
    3 6
    3 7
    
    Expected output
    2
    
  2. Example 2

    Input
    10
    0 0 1 0 2 1 0 2 2 2
    3 1
    1 4
    9 5
    10 5
    1 2
    3 6
    3 5
    5 8
    4 7
    
    Expected output
    2