D. Reds and Blues
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

There are two groups of people in the country of Berland, the Red's and the Blue's. There are also $$$n$$$ cities which are connected by a set of $$$m$$$ roads such that each of the roads have some edge weight cost associated with building them. Both the Red's and the Blue's want to be able to travel between all the cities they have claimed (they can travel through cities claimed by the other party if needed if it is on the path to a city of their own color). What's the minimum cost of roads they must build such that all Red cities and all Blue cities are connected within each color?

Input

The first line contains $$$N$$$ and $$$M$$$. ($$$1 \le N, M \le 2 \cdot 10^5$$$).

The second line contains a string $$$S$$$ of length $$$N$$$. $$$S[i]$$$, $$$i \in [1, n]$$$ is the color of a city, either 'R' or 'B' for red and blue respectively.

The next $$$M$$$ lines contain three integers, $$$u$$$, $$$v$$$, and $$$w$$$ indicating that cities $$$u$$$ and $$$v$$$ have a potential road that can be built between them with cost $$$w$$$.

It is guaranteed that the graph is fully connected.

Output

Print a single integer indicating the minimum cost of building the roads such that all red and all blue cities are connected.

Example
Input
5 5
RBRRB
1 3 1
4 3 1
2 5 2
1 2 4
2 3 4
Output
4