P9661 [ICPC 2021 Macao R] Sandpile on Clique

题目描述

阿贝尔沙堆模型(Abelian Sandpile Model)是一个著名的显示自组织临界性的动力学系统。自从它由 Per Bak、Chao Tang 和 Kurt Wiesenfeld 在 1987 年的一篇论文中引入以来,它已经被研究了数十年。沙堆模型的预测引起了物理学、计算机科学和数学的广泛关注,这不仅是因为它美丽的代数结构,还因为它与负载平衡和内部扩散有关的模型的应用,如去随机化。沙堆模型与许多其他模型和物理现象相关,如转子路由模型、雪崩模型。 在沙堆模型中,给定一个顶点编号从 $1$ 到 $n$ 的无向图 $G$。我们还给出了 $n$ 个整数 $a_1, a_2, \cdots, a_n$,其中 $a_i$ 表示初始时放置在顶点 $i$ 上的筹码数量。每个回合,我们将选择一个任意的顶点 $v$,使得 $v$ 上的筹码数量不小于与 $v$ 相连的边数,记为 $d_v$。对于 $v$ 的每个邻居,它将从 $v$ 接收一枚筹码。因此,$v$ 将失去 $d_v$ 枚筹码。这个过程被称为 ``firing`` 或 ``toppling``。直到没有顶点 $v$ 至少有 $d_v$ 枚筹码时,firing 才会停止。 可以证明,firing 的顺序不会影响结果。同时,也可能 firing 永远不会终止。这种情况被描述为“recurrent”。现在给定一个团和初始筹码数量,请确定这个实例是否是一个 recurrent 实例。如果不是,请分别输出每个节点的最终筹码数量。 团(也称为完全图)是一个图,其中任意两个顶点都有边相连。

输入格式

输出格式

说明/提示

For the first sample test case: - We can only select vertex $1$ at the beginning. The number of chips becomes $\{1, 1, 4, 1, 4\}$. - We can now select vertex $3$ or $5$ because both of them have at least $4$ chips. We select vertex $3$ and the number of chips becomes $\{2, 2, 0, 2, 5\}$. Selecting vertex $5$ will lead to the same result. - We now select vertex $5$. The number of chips becomes $\{3, 3, 1, 3, 1\}$. There is no vertex with at least $4$ chips so the firing terminates. For the second sample test case, we can select vertex $1$ and $2$ repeatedly. The firing never terminates.