Colored Sticks
| Time Limit: 5000MS | Memory Limit: 128000K | |
| Total Submissions: 16750 | Accepted: 4248 |
Description
You are given a bunch of wooden sticks. Each endpoint of each stick is colored with some color. Is it possible to align the sticks in a straight line such that the colors of the endpoints that touch are of the same color?
Input
Input is a sequence of lines, each line contains two words, separated by spaces, giving the colors of the endpoints of one stick. A word is a sequence of lowercase letters no longer than 10 characters. There is no more than 250000 sticks.
Output
If the sticks can be aligned in the desired way, output a single line saying Possible, otherwise output Impossible.
Sample Input
blue redred violetcyan blueblue magentamagenta cyan
Sample Input
blue redred violetcyan blueblue magentamagenta cyan
Sample Output
Possible
Hint
Huge input,scanf is recommended.
本文介绍了一个有趣的问题:如何判断一组两端涂有不同颜色的木棍能否首尾相连形成一条直线。文章通过图论中的欧拉通路概念给出了解决方案,并提供了一段C++实现代码。
7387

被折叠的 条评论
为什么被折叠?



