Sandpile on Clique
Time limit1sMemory limit1024 MB
Given a clique with chip counts on each vertex, determine whether toppling never stops; if it stops, output the final chip count of every vertex.
- Level
Hard9 of 10
- Topics
- Math, Sorting, Implementation
- Solved
- No attempts yet
Problem
The Abelian Sandpile Model is a well-known dynamical system that shows self-organized criticality. Per Bak, Chao Tang, and Kurt Wiesenfeld introduced it in a 1987 paper, and researchers have studied it for decades. The sandpile model draws interest in physics, computer science, and mathematics. Its algebraic structure is elegant, and it applies to load balancing and to the derandomization of models such as internal diffusion-limited aggregation. The model is also related to the rotor-routing model and avalanche models.
In the sandpile model, we are given an undirected graph whose vertices are numbered from to . We are also given integers , where is the number of chips initially placed on vertex .
Each turn, we pick any vertex whose chip count is at least , the number of edges connected to . Each neighbor of receives one chip from , so loses chips. This is called firing or toppling. Firing continues until no vertex has at least chips.
The order of firing does not affect the result. However, firing may never terminate. In that case the instance is called "recurrent". You are given a clique (a complete graph, where every two vertices are connected by an edge) and the initial chip counts. Determine whether the instance is recurrent. If it is not, output the final chip count of each vertex.
Input
The first line contains an integer (), the size of the clique.
The second line contains integers (), where is the initial number of chips on vertex .
There is only one test case per input file.
Output
If the firing terminates, output integers separated by spaces, where the -th integer is the final number of chips on vertex . Otherwise, output "Recurrent".
Hint
For the first sample, only vertex 1 can be chosen at the start. The chip counts become {1, 1, 4, 1, 4}.
Now vertex 3 or vertex 5 can be chosen, since both have at least 4 chips. Choosing vertex 3 gives {2, 2, 0, 2, 5}. Choosing vertex 5 gives the same result.
Next, vertex 5 is chosen, giving {3, 3, 1, 3, 1}. No vertex has at least 4 chips, so firing stops.
For the second sample, vertices 1 and 2 can be chosen repeatedly. Firing never terminates.