| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 512 MB | 17 | 8 | 6 | 40.000% |
You are given a sequence of $n$ characters 0 or 1, indexed by numbers 1,ドル 2, \dots , n$. Initially every character represents a string of length one. During a concatenation two words $a$ and $b$ are chosen, deleted, and replaced by the string $ab$ such that the characters of $b$ are written after the characters of $a$.
The $n$ initial strings are concatenated to one final string using a sequence of $n-1$ concatenations. The $i$-th of those concatenation is described by a pair of indexes $(a_i , b_i),ドル which denotes that the string containing $a_i$-th character and the string containing $b_i$-th character are to be concatenated. It is guaranteed that characters with indexes $a_i$ and $b_i$ are not in the same string.
Palindromic value of some string $w$ is defined as the total number of unique substrings of $w$ which are palindromes. We define palindromes as strings that are the same when read left to right and right to left. A substring of a string is defined as a string obtained by erasing zero or more characters from the beginning and/or ending of the string.
For every concatenation print the palindromic value of the resulting string.
The first line contains an integer $n$ (1ドル ≤ n ≤ 100,000円$), number of characters.
In the second line there is a string of $n$ characters 0 and 1 which represent the initial strings.
The $i$-th of following $n - 1$ lines contains two integers $a_i$ and $b_i$ (1ドル ≤ a_i , b_i ≤ n,ドル $a_i \ne b_i$) representing the $i$-th concatenation.
Print $n - 1$ lines, the palindromic values of words obtained after each concatenation.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 10 | 1ドル ≤ n ≤ 100$. |
| 2 | 20 | 1ドル ≤ n ≤ 1000$. |
| 3 | 30 | $a_i = 1,ドル $b_i = i + 1$ for all $i = 1, 2, \dots , n - 1$. |
| 4 | 50 | No additional constraints. |
3 010 1 2 2 3
2 3
5 00111 4 1 1 5 2 1 3 1
2 3 4 5
8 10010000 7 5 4 2 3 6 1 3 6 8 5 3 1 2
2 2 2 3 4 6 8
Clarification of the third example:
Newly created strings after every concatenation are: 00, 10, 00, 100, 1000, 001000 and 00100010. Their respective palindromic values are given in the example output. E. g. the palindromic value of 00100010 is 8 because the string contains 8 palindromic substring: 0, 00, 000, 10001, 0100010, 1, 010 and 00100.