QOJ.ac

QOJ

حد الوقت: 2 s حد الذاكرة: 512 MB مجموع النقاط: 100

#3841. 完全图上的沙堆模型

الإحصائيات

Abelian Sandpile Model(阿贝尔沙堆模型)是一个著名的动力系统,展现了自组织临界性。自 Per Bak、Chao Tang 和 Kurt Wiesenfeld 在 1987 年的论文中提出该模型以来,它已被研究了数十年。沙堆预测在物理学、计算机科学和数学领域引起了广泛关注,这既归功于其优美的代数结构,也归功于它在负载均衡和诸如内扩散限制聚集(internal diffusion-limited aggregation)等模型的去随机化应用中的相关性。沙堆模型与许多其他模型和物理现象(如转子路由模型、雪崩模型)有关。

在沙堆模型中,给定一个无向图 $G$,其顶点编号为 $1$ 到 $n$。同时给定 $n$ 个整数 $a_1, a_2, \dots, a_n$,其中 $a_i$ 表示初始时放置在顶点 $i$ 上的筹码数量。每一轮,我们将选择一个任意顶点 $v$,使得 $v$ 上的筹码数不小于与 $v$ 相连的边数(记为 $d_v$)。对于 $v$ 的每个邻居,它将从 $v$ 接收一个筹码。因此,$v$ 将失去 $d_v$ 个筹码。这个过程被称为“激发”或“坍塌”。激发过程将持续进行,直到没有顶点 $v$ 的筹码数达到 $d_v$ 为止。

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

团(也称为完全图)是指图中每两个顶点之间都有一条边相连的图。

输入格式

每个测试文件中仅包含一组测试数据。

第一行包含一个整数 $n$ ($2 \le n \le 5 \times 10^5$),表示团的大小。

第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 10^9$),其中 $a_i$ 表示初始放置在顶点 $i$ 上的筹码数量。

输出格式

输出一行。如果给定的沙堆实例会终止,输出 $n$ 个由空格分隔的整数,其中第 $i$ 个整数表示第 $i$ 个顶点上的最终筹码数。否则,输出 “Recurrent”(不含引号)。

请注意,不要在每行末尾输出多余的空格,否则你的解法可能会被判定为错误!

样例

输入 1

5
5 0 3 0 3

输出 1

3 3 1 3 1

输入 2

2
1 0

输出 2

Recurrent

说明

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

  • 开始时我们只能选择顶点 1。筹码数量变为 $\{1, 1, 4, 1, 4\}$。
  • 现在我们可以选择顶点 3 或 5,因为它们都有至少 4 个筹码。我们选择顶点 3,筹码数量变为 $\{2, 2, 0, 2, 5\}$。选择顶点 5 会导致相同的结果。
  • 现在我们选择顶点 5。筹码数量变为 $\{3, 3, 1, 3, 1\}$。此时没有顶点拥有至少 4 个筹码,因此激发终止。

对于第二个样例测试用例,我们可以重复选择顶点 1 和 2。激发过程永远不会终止。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.