| 2025 ICPC, Chula Selection Contest |
|---|
| Finished |
It's Christmas Eve! Santa Claus takes a quick trip in his time machine to visit his good friend, Doraemon, in the 22nd century. Seeing Santa so busy, Doraemon offers to help with a futuristic sleigh and some amazing gadgets!
This year, they are delivering two special items:
But Doraemon has a strict rule from his "Future Gadget Rulebook" to make sure the deliveries are perfect:
So, for each delivery, Santa must travel from Doraemon's workshop to one kid's house and come straight back to the workshop to pick up the next item. Your job is to help Santa and Doraemon find the shortest total distance they need to travel to deliver everything correctly.
You are given a map with Doraemon's workshop and all the kids' houses. The roads connect these places, and each road has a certain length. Every house is either a "Good Kid" house or a "Bad Kid" house.
Santa has to make one trip for each and every house:
Here are the two very important rules for the path from the workshop to the house, and from the house back to the workshop:
You are guaranteed that Santa can always find a way to reach every house by following these rules.
The first line has one number, $$$n$$$ ($$$1 \le n \le 10^5$$$), which is how many houses there are.
The second line has a string of $$$n$$$ letters. Each letter tells you the type of a house. 'G' is for a Good kid's house, and 'B' is for a Bad kid's house.
The third line has one number, $$$m$$$ ($$$1 \le m \le 3 \cdot 10^5$$$), which is how many roads there are on the map.
The next $$$m$$$ lines describe the roads. Each line has three numbers: $$$u$$$, $$$v$$$, and $$$d$$$ ($$$0 \le u,v \le n, 1 \le d \le 10^6$$$). This means there is a road between place $$$u$$$ and place $$$v$$$ with a distance of $$$d$$$. Place $$$0$$$ is Doraemon's workshop, and places $$$1$$$ to $$$n$$$ are the houses.
Print one single number — the shortest total distance Santa must travel for all the deliveries combined.
3GBG40 1 100 2 121 3 52 3 6
74
| Name |
|---|


