当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6947:Stacks

题目描述
There are $N$ stacks, numbered from $1$ to $N$. Initially, the $i$-th stack only contains a number $i$. Now there are $M$ move operations, and the $i$-th operation is to move all the numbers in stack $a_i$ to stack $b_i$. Specifically speaking, we pop all the numbers in stack $a_i$ one by one, and push them to stack $b_i$ in the order of popping (the first to be popped is the first to be pushed).

After all the $M$ operations, you should output the numbers in the stacks.
输入解释
There are multiple test cases.

For each test case, the first line contains $2$ integers $N$ and $M$ $(1\leq M \leq N \leq 10^5)$.

In the next $M$ lines, each line contains $2$ integers $a_i$ and $b_i$ $(1\leq a,b \leq N, ~ a\neq b)$, denoting an operation.

It's guaranteed that the sum of $N$ of all the test cases is no more than $2 \cdot 10^5$.
输出解释
For each test case, print $n$ lines. The $i$-th line begins with an integer $S_i$, denoting the number of numbers in the $i$-th stack, followed by $S_i$ integers, denoting the numbers in the $i$-th stack from top to bottom.
输入样例
6 5
1 2
2 3
3 4
4 5
6 2
输出样例
0
1 6
0
0
5 4 2 1 3 5
0

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6947

最后修改于 2021-10-23T19:10:47+00:00 由爬虫自动更新

共提交 1

通过率 0.0%
时间上限 内存上限
2000/1000MS(Java/Others) 65536/262144K(Java/Others)