WC '18 Contest 4 S1 - World of StarCraft

View as PDF

Submit solution


Points: 10 (partial)
Time limit: 1.4s
Memory limit: 128M

Author:
Problem type
Woburn Challenge 2018-19 Round 4 - Senior Division

Billy, the king of video games, is (among other things) a top professional StarCraft II player. In light of his recent success as the only human to defeat the fearsome AlphaStar AI, he has received exclusive access to play the upcoming installment in the series, World of StarCraft. In a natural progression for the series, this is a massively multiplayer online role-playing game.

World of StarCraft features N (2 \le N \le 100\,000) planets, numbered from 1 to N. Each planet is under the control of one of three races (Protoss, Terran, or Zerg), with the character R_i representing planet i's race (either P for Protoss, T for Terran, or Z for Zerg).

There are M (0 \le M \le 100\,000) space routes running amongst the planets, with the i-th space route allowing one to travel in either direction between planets A_i and B_i (1 \le A_i, B_i \le N, A_i \ne B_i). There may be multiple space routes connecting a single pair of planets.

Despite its secretive and unreleased development status, World of StarCraft somehow already has an enormous player-base. Billy himself has K (1 \le K \le 100\,000) friends in the game. His i-th friend is currently on planet X_i, and would like to reach a different planet Y_i to complete an objective (1 \le X_i, Y_i \le N; X_i \ne Y_i).

When a player is on planet i, they may travel along a space route to another planet j, assuming that a space route exists which connects planets i and j. However, due to open hostilities amongst the three races, it's only safe to do so if both planets are under the control of the same race (in other words, if R_i = R_j).

Billy would love to help all of his friends complete their objectives, but not without putting their in-game lives at risk! Help him determine how many friends i he has such that it's possible to safely travel through a sequence of planets beginning at planet X_i and ending at planet Y_i.

Subtasks

In test cases worth 8/14 of the points, N \le 1\,000, M \le 1\,000, and K \le 1\,000.

Input Specification

The first line of input consists of three space-separated integers, N, M, and K.
The next line consists of characters, R_{1 \dots N}.
M lines follow, the i-th of which consists of two space-separated integers, A_i and B_i, for i = 1 \dots M.
K lines follow, the i-th of which consists of two space-separated integers, X_i and Y_i, for i = 1 \dots K.

Output Specification

Output a single integer, the number of friends who can safely complete their objectives.

Sample Input

6 7 3
PZZPPP
1 2
6 4
3 4
2 5
5 6
1 4
4 2
6 4
2 3
1 5

Sample Output

2

Sample Explanation

Billy's first friend can safely travel directly from planet 6 to planet 4 to complete their objective.

Billy's second friend may never safely reach planet 3.

Billy's third friend can safely travel through the sequence of planets 1 \to 4 \to 6 \to 5.


Comments

There are no comments at the moment.