#P9661. [ICPC2021 Macao R] Sandpile on Clique
[ICPC2021 Macao R] Sandpile on Clique
题目描述
The is a famous dynamical system displaying self-organized criticality. It has been studied for decades since it was introduced by Per Bak, Chao Tang and Kurt Wiesenfeld in a 1987 paper. The sandpile prediction is of wide interest in physics, computer science, and mathematics, both for its beautiful algebraic structure and for its relevance to applications like load balancing and derandomization of models like internal diffusion-limited aggregation. The sandpile model is related to many other models and physical phenomena, like the rotor-routing model, avalanche models.
In the sandpile model, we are given an undirected graph whose vertices are indexed from to . We're also given integers where indicates that there are chips placed on vertex initially. Each turn we will pick an arbitrary vertex such that the number of chips on is not smaller than the number of edges connecting , denoted as . For each neighbor of , it will receive one chip from . Therefore, will lost chips. This process is called firing or toppling. Firing will keep happening until no vertex has at least chips.
It can be proven that the order of firing doesn't affect the result. Meanwhile, it is also possible that the firing will never terminate. This instance is described as recurrent
. Now you are given a clique and the initial number of chips. Determine whether this instance is a recurrent one. If not, please output the final number of chips for each node respectively.
A clique (also called a complete graph) is a graph where every two vertices are connected with an edge.
输入格式
There is only one test case in each test file.
The first line of the input contains an integer () indicating the size of the clique.
The second line contains integers () where indicates the initial number of chips placed on vertex .
输出格式
Output one line. If the given sandpile instance will terminate, output integers separated by a space where the -th integer indicates the final number of chips on the -th vertex. Otherwise output Recurrent
(without quotes) instead.
Please, DO NOT output extra spaces at the end of each line or your solution may be considered incorrect!
5
5 0 3 0 3
3 3 1 3 1
2
1 0
Recurrent
提示
For the first sample test case:
- We can only select vertex at the beginning. The number of chips becomes .
- We can now select vertex or because both of them have at least chips. We select vertex and the number of chips becomes . Selecting vertex will lead to the same result.
- We now select vertex . The number of chips becomes . There is no vertex with at least chips so the firing terminates.
For the second sample test case, we can select vertex and repeatedly. The firing never terminates.