#P9661. [ICPC2021 Macao R] Sandpile on Clique

    ID: 8978 Type: RemoteJudge 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 4 Uploaded By: Tags>2021O2优化ICPCAd-hoc澳门

[ICPC2021 Macao R] Sandpile on Clique

题目描述

The Abelian Sandpile Model\textit{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 GG whose vertices are indexed from 11 to nn. We're also given nn integers a1,a2,,ana_1, a_2, \cdots, a_n where aia_i indicates that there are aia_i chips placed on vertex ii initially. Each turn we will pick an arbitrary vertex vv such that the number of chips on vv is not smaller than the number of edges connecting vv, denoted as dvd_v. For each neighbor of vv, it will receive one chip from vv. Therefore, vv will lost dvd_v chips. This process is called firing or toppling. Firing will keep happening until no vertex vv has at least dvd_v 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 nn (2n5×1052 \leq n \leq 5 \times 10^5) indicating the size of the clique.

The second line contains nn integers a1,a2,,ana_1, a_2, \cdots, a_n (0ai1090 \leq a_i \leq 10^9) where aia_i indicates the initial number of chips placed on vertex ii.

输出格式

Output one line. If the given sandpile instance will terminate, output nn integers separated by a space where the ii-th integer indicates the final number of chips on the ii-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!

题目大意

【题目描述】

阿贝尔沙堆模型(Abelian Sandpile Model)是一个著名的显示自组织临界性的动力学系统。自从它由 Per Bak、Chao Tang 和 Kurt Wiesenfeld 在 1987 年的一篇论文中引入以来,它已经被研究了数十年。沙堆模型的预测引起了物理学、计算机科学和数学的广泛关注,这不仅是因为它美丽的代数结构,还因为它与负载平衡和内部扩散有关的模型的应用,如去随机化。沙堆模型与许多其他模型和物理现象相关,如转子路由模型、雪崩模型。

在沙堆模型中,给定一个顶点编号从 11nn 的无向图 GG。我们还给出了 nn 个整数 a1,a2,,ana_1, a_2, \cdots, a_n,其中 aia_i 表示初始时放置在顶点 ii 上的筹码数量。每个回合,我们将选择一个任意的顶点 vv,使得 vv 上的筹码数量不小于与 vv 相连的边数,记为 dvd_v。对于 vv 的每个邻居,它将从 vv 接收一枚筹码。因此,vv 将失去 dvd_v 枚筹码。这个过程被称为 firingtoppling。直到没有顶点 vv 至少有 dvd_v 枚筹码时,firing 才会停止。

可以证明,firing 的顺序不会影响结果。同时,也可能 firing 永远不会终止。这种情况被描述为“recurrent”。现在给定一个团和初始筹码数量,请确定这个实例是否是一个 recurrent 实例。如果不是,请分别输出每个节点的最终筹码数量。

团(也称为完全图)是一个图,其中任意两个顶点都有边相连。

【输入格式】

每个测试文件中只有一个测试用例。

输入的第一行包含一个整数 nn2n5×1052 \leq n \leq 5 \times 10^5),表示团的大小。

第二行包含 nn 个整数 a1,a2,,ana_1, a_2, \cdots, a_n0ai1090 \leq a_i \leq 10^9),其中 aia_i 表示放置在顶点 ii 上的初始筹码数量。

【输出格式】

输出一行。如果给定的沙堆实例将终止,则输出由空格分隔的 nn 个整数,其中第 ii 个整数表示第 ii 个顶点上的最终筹码数量。否则输出 Recurrent(不包括引号)。

请不要在每行末尾输出额外的空格,否则您的解决方案可能被认为是错误的!

【样例解释】

对于第一个样例测试用例:

  • 我们只能在开始时选择顶点 11。筹码数量变为 {1,1,4,1,4}\{1, 1, 4, 1, 4\}
  • 现在我们可以选择顶点 3355,因为它们都至少有 44 枚筹码。我们选择顶点 33,筹码数量变为 {2,2,0,2,5}\{2, 2, 0, 2, 5\}。选择顶点 55 会得到相同的结果。
  • 现在我们选择顶点 55。筹码数量变为 {3,3,1,3,1}\{3, 3, 1, 3, 1\}。没有顶点至少有 44 枚筹码,因此 firing 终止。

对于第二个样例测试用例,我们可以重复选择顶点 1122。firing 永远不会终止。

翻译来自于:ChatGPT

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 11 at the beginning. The number of chips becomes {1,1,4,1,4}\{1, 1, 4, 1, 4\}.
  • We can now select vertex 33 or 55 because both of them have at least 44 chips. We select vertex 33 and the number of chips becomes {2,2,0,2,5}\{2, 2, 0, 2, 5\}. Selecting vertex 55 will lead to the same result.
  • We now select vertex 55. The number of chips becomes {3,3,1,3,1}\{3, 3, 1, 3, 1\}. There is no vertex with at least 44 chips so the firing terminates.

For the second sample test case, we can select vertex 11 and 22 repeatedly. The firing never terminates.