#P15533. 【MYCOI R1】那友谊连成的树
【MYCOI R1】那友谊连成的树
Description
In Xiao Che and Xiao Meng's school, there are students. They are divided into two types: introverted and extroverted.
There are some friendships among the students. Define to mean that student and student are good friends.
For two students , if there exists a sequence of students such that , , , , then is called a "spacing" between and . The "friend distance" is defined as the minimum "spacing" between and .
Thus, the "friend distance" between good friends is .
Upon entering school (the morning of the first day), the students, for various reasons, have formed pairs of good friends, and there exists a "friend distance" between any two students. In other words, if we regard the students as nodes on a tree and the good friend relationships as edges between nodes, the initial relationships among the students form a tree.
The students enjoy making friends. Each day, for any three students , if and are both "extroverted", and on the morning of that day and are good friends, and and are good friends, then at noon that day and will become good friends (note that can be "introverted"). As a result, the "friend distance" between students will gradually decrease.
However, as time goes on, the pressure of academic courses increases, and students spend more time studying rather than socializing. Therefore, on the evening of day , the "social cost" between and is .
Xiao Che and Xiao Meng want to know, if they are students and , what is the minimum "social cost" among the evenings from day to day ?
Input Format
The first line contains two positive integers , representing the number of students and the number of queries.
The second line contains characters. The -th character represents the personality of student (I for introverted, E for extroverted).
The next lines each contain two positive integers , indicating that and are good friends on the morning of the first day.
The last lines each contain three positive integers , as described above.
Output Format
For each query, output a line containing a positive integer representing the answer.
7 3
IEEIEIE
1 2
4 6
5 7
1 3
3 7
3 4
4 5 1
4 5 3
2 5 10
3
3
4
Hint
This problem uses bundled testing.
::cute-table{tuack}
| Subtask | Special Properties | Points |
|---|---|---|
| Subtask 1 | 30 | |
| Subtask 2 | Initially, exactly students have exactly good friend, and the remaining students have exactly good friends. | 5 |
| Subtask 3 | Initially, there exists a student who has "good friends". | 10 |
| Subtask 4 | All students are extroverted. | 15 |
| Subtask 5 | ||
| Subtask 6 | No special properties | 25 |
For of the data: , , , .
京公网安备 11011102002149号