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 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 lose
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.
Input Specification
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 Specification
Output one line. If the given sandpile instance will terminate, output integers separated by a space
where the
integer indicates the final number of chips on the
vertex. Otherwise 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 and
repeatedly. The firing never terminates.
Comments