经典简约
清爽简洁,回归本真
液态水晶
毛玻璃+霓虹光带
赛博朋克
霓虹故障艺术风
🚫
违规操作检测
禁止使用右键菜单
⚠️ 此操作已被系统记录
1

Pick up sticks

📝 题解 🔵 仅限 C++
题目描述
<p> Pick up sticks is a fascinating game. A collection of coloured sticks are dumped in a tangled heap on the table. Players take turns trying to pick up a single stick at a time without moving any of the other sticks. It is very difficult to pick up a stick if there is another stick lying on top of it. The players therefore try to pick up the sticks in an order such that they never have to pick up a stick from underneath another stick.<img src="http://tk.hustoj.com/upload/image/20170420/20170420084432_77697.png" alt="" /> </p>
输入格式
<p> The input consists of several test cases. The first line of each test case contains two integers <i>n</i> and <i>m</i> each at least one and no greater than one million. The integer <i>n</i> is the number of sticks, and <i>m</i> is the number of lines that follow. The sticks are numbered from 1 to <i>n</i>. Each of the following lines contains a pair of integers <i>a</i>, <i>b</i>, indicating that there is a point where stick <i>a</i> lies on top of stick <i>b</i>. The last line of input is0 0. These zeros are not values of <i>n</i> and <i>m</i>, and should not be processed as such. </p>
输出格式
<p> For each test case, output <i>n</i> lines of integers, listing the sticks in the order in which they could be picked up without ever picking up a stick with another stick on top of it. If there are multiple such correct orders, any one will do. If there is no such correct order, output a single line containing the wordIMPOSSIBLE. </p>
样例
样例输入 1
3 2 1 2 2 3 0 0
样例输出 1
1 2 3
提交代码
请先登录后提交

🤖 AI 解题助手

DeepSeek
就绪
👋 你好!我是 AI 解题助手。
我已阅读了这道题,可以帮你分析思路、提供代码示例。
⚠️ 请先登录后使用