Under construction

Still being built. Things may change

What Handle Should I Pick

Interview

Time limit1sMemory limit1024 MB

Summary
Given a tree with a letter on each vertex, find the lexicographically largest string spelled by a walk from vertex 1 to a leaf.
Level

Medium4 of 10

Topics
Tree, BFS, Greedy
Solved
No attempts yet

Problem

Online judges identify each user by a unique ID. This ID is also called a handle, and the same or similar ID is usually used across several sites. For this reason, competitive programmers who are active on several sites are often better known by their handles than by their real names.

Gyu-hyo dreams of reaching the top of competitive programming, but he is stuck on choosing a handle. He wants one that sounds cool and also means something, but nothing comes to mind. Sang-won, who was watching him struggle, pulled a tree out of his pocket and suggested a way to pick one.

  1. The tree has NN vertices numbered from 11 to NN, and each vertex has a lowercase English letter written on it.
  2. Start at vertex 11.
  3. From the current vertex, move to an adjacent vertex that has not been visited yet. Repeat this until no further move is possible.
  4. Concatenate the letters on the visited vertices in the order they were visited.

Gyu-hyo uses the resulting string as his handle. There are too many possible strings, so he decides to take the one that comes last in dictionary order. Given the tree that Sang-won gave him, find the handle Gyu-hyo will choose.

Input

The first line contains NN. (1≤N≤500 000)(1 \le N \le 500\,000)

The second line contains the lowercase letters written on the vertices, in order, with no spaces.

Each of the next N−1N-1 lines contains two integers uu and vv separated by a space. They describe an edge between vertex uu and vertex vv. (1≤u,v≤N,u≠v)(1 \le u, v \le N, u \neq v)

Output

Print the handle Gyu-hyo will choose.

Examples2

  1. Example 1

    Input
    8
    dfcjsasb
    8 4
    6 3
    1 3
    2 1
    4 1
    4 7
    2 5
    
    Expected output
    djs
    
  2. Example 2

    Input
    7
    aaaaaaa
    1 2
    1 3
    3 4
    3 5
    5 6
    5 7
    
    Expected output
    aaaa