Classic
Clean & simple
Crystal
Glassmorphism + Neon
Cyberpunk
Neon glitch art
🚫
违规Action检测
禁止Use右键菜单
⚠️ 此Action已被系统记录
1

Pick up sticks

📝 Solutions 🔵 仅限 C++
Problems Description
<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>
Input格式
<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>
Output格式
<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>
Sample
Sample Input 1
3 2 1 2 2 3 0 0
Sample Output 1
1 2 3
Submit Code
请先Login后Submit

🤖 AI 解题助手

OpenRouter
就绪
👋 你好!我是 AI 解题助手。
我已阅读了这problems题,可以帮你points析思路、提供Code示例。
🔓 完全Free · 无需消耗 Token