Highway Hoax

Time limit: 0.7s Memory limit: 256MB Input: Output:

You think this is something? You think this is bad? This? This chicanery?

  • Chuck McGill, Better Call Saul

Albuquerque is a large city. It has nn crossings and n1n-1 one-directional highways between them. It's guaranteed that if all highways were undirected, it would be possible to get from any crossing to any other by these highways. Additionally, every crossing has a label: S or F, indicating start and finish correspondingly.

Saul and Kim are going to do another chicanery. They can perform the following operation any number of times:

  • Choose any highway (u,v)(u, v) such that the following conditions hold:
    • This highway is directed from crossing uu to crossing vv
    • Crossing uu has label S
    • Crossing vv has label F
  • Change the direction of the highway and swap labels on uu and vv.

What is the total number of different configurations that Saul and Kim can achieve by applying this operation any number of times? As this number can be very large, output it modulo 998 244 353998 \ 244 \ 353.

Two configurations are called different if some crossing has different labels in them, or if some highway has different orientation in them.

Input data

The first line of the input contains a single integer nn (2n21052 \leq n \leq 2\cdot 10^5) - the number of crossings in Albuquerque.

The second line of the input contains a string of length nn, consisting of characters S and F. The ii-th character of this string denotes the initial label of crossing ii.

The ii-th of the next n1n-1 lines contains two integers ui,viu_i, v_i (1ui,vin1 \leq u_i, v_i \leq n, uiviu_i \neq v_i) - denoting a directed highway from crossing uiu_i to crossing viv_i. It's guaranteed that if all highways were undirected, it would be possible to get from any crossing to any other by these highways.

Output data

Output a single integer - the total number of different configurations that Saul and Kim can achieve by applying this operation any number of times, modulo 998 244 353998 \ 244 \ 353.

Example 1

stdin

1 2

stdout

3

Explanation

In the first sample, all highways are directed from crossings with F on them to crossings with S on them, so it's impossible to do any operations.

Example 2

stdin

5 -1

stdout

4

Explanation

In the second sample, for each v=2,3,4v = 2, 3, 4 it's possible to do an operation with nodes 1,v1, v. Resulting three configurations, together with the initial one, are the only possible configurations.

Example 3

stdin

5 -1

stdout

4

Log in or sign up to be able to send submissions!