시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 | 512 MB | 61 | 2 | 2 | 40.000% |
In a galaxy far, far away..., there are N highly civilized stars numbered from 1 to N. Each star provides one teleporter. Each teleporter has a fixed destination. We travel through a teleporter only in one direction.
The Galactic Empire Museum of Art holds art exhibitions in stars in the galaxy. Now the exhibition is held in the star 1. The next exhibition will be held in the star where we travel from the star 1 using the teleporters K times.
The Space Police found that a space pirate is planning to steal collections of the museum. The space pirate will crack into the teleporter system, and illegally overwrite the destination of the teleporter in the star a. The destination of the teleporter in the star a will be modified to the star b. The space pirate will crack into the teleporter system of one star only. However, the Space Police could not find the precise values of a, b.
In order to predict the location of the next exhibition, the Space Police would like to know, for each i, the number of pairs (a, b) such that the next exhibition will be held in the star i. To calculate these numbers is a difficult job. Since you are a good programmer, the Space Police asked you to calculate them.
Given the destination of each teleporter, for each i, calculate the number of pairs (a, b) such that the next exhibition will be held in the star i.
Read the following data from the standard input.
All input data satisfy the following conditions.
Write N lines to the standard output. The i-th line (1 ≤ i ≤ N) should contain an integer, the number of pairs (a, b) such that the next exhibition will be held in the star i.
번호 | 배점 | 제한 |
---|---|---|
1 | 10 | N ≤ 100. |
2 | 37 | N ≤ 3 000. |
3 | 33 | Ai ≠ Aj (1 ≤ i < j ≤ N). |
4 | 20 | There are no additional constraints. |
5 7 5 1 4 3 2
1 2 3 3 16
40 57 9 24 1 28 29 5 9 1 36 5 35 14 14 29 28 34 28 4 34 36 33 11 22 23 10 18 26 33 36 15 37 31 27 16 25 37 6 31 21 31
4 2 1 12 18 9 1 1 15 0 4 0 0 2 0 11 0 12 0 2 0 0 1 0 5 12 13 13 34 0 5 1 15 10 8 1351 36 1 0 1
Note
Sample Input 1
The destination of each teleporter is described in Figure 1.
Figure 1
If (a, b) = (1, 4), the destination of the teleporter in the star 1 will be overwritten to the star 4. The destination of each teleporter will become as in Figure 2. We will arrive at the star 4 if we travel from the star 1 using the teleporters 7 times. Therefore, the next exhibition will be held in the star 4. (We travel as 1 → 4 → 3 → 4 → 3 → 4 → 3 → 4 using the teleporters.)
![]() |
![]() |
![]() |
Figure 2 | Figure 3 | Figure 4 |
There are three pairs of (a, b) (i.e. (1, 4), (2, 4), (5, 3)) where the next exhibition will be held in the star 4. The location of the next exhibition for each pair (a, b) is summarized in the following table.
1 | (1,1) |
---|---|
2 | (1,2), (2,2) |
3 | (1,3), (2,3), (5,4) |
4 | (1,4), (2,4), (5,3) |
5 | (1,5), (2,1), (2,5), (3,1), (3,2), (3,3), (3,4), (3,5), (4,1), (4,2) (4,3), (4,4), (4,5), (5,1), (5,2), (5,5) |
When you count the number of pairs (a, b), the pairs (a, b) with a = b should be counted. You should also count the pairs (a, b) such that the destination of the teleporter will not be changed.