2023 Winter Waterloo Local Contest, Problem C
The Abelian Sandpile Model 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
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.
Input Specification
There is only one test case in each test file.
The first line of the input contains an integer
The second line contains
Output Specification
Output one line. If the given sandpile instance will terminate, output Recurrent
instead.
Please, DO NOT output extra spaces at the end of each line, or your answer may be considered incorrect!
Sample Input 1
5
5 0 3 0 3
Sample Output 1
3 3 1 3 1
Explanation for Sample 1
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.
Sample Input 2
2
1 0
Sample Output 2
Recurrent
Explanation for Sample 2
For the second sample test case, we can select vertex
Comments