欧拉回路-有向图-B - Play on Words

考古学家面临一个有趣的字谜挑战,必须解决才能打开秘密门。每个门上都有磁性板块,板块上的单词需按特定规则排列:每个单词的第一个字母须与前一个单词的最后一个字母相同。任务是编写程序检查单词列表,判断能否按规则排列所有单词。输入包含测试用例,每个用例包含单词数量和单词列表。输出是判断能否形成这样的序列。如果存在这样的排列,输出"Ordering is possible.",否则输出"The door cannot be opened."。问题可转化为有向图中是否存在欧拉通路的问题。
摘要由CSDN通过智能技术生成

 

Some of the secret doors contain a very interesting word puzzle. The team of archaeologists has to solve it to open that doors. Because there is no other way to open the doors, the puzzle is very important for us. 

There is a large number of magnetic plates on every door. Every plate has one word written on it. The plates must be arranged into a sequence in such a way that every word begins with the same letter as the previous word ends. For example, the word ``acm'' can be followed by the word ``motorola''. Your task is to write a computer program that will read the list of words and determine whether it is possible to arrange all of the plates in a sequence (according to the given rule) and consequently to open the door. 

Input

The input consists of T test cases. The number of them (T) is given on the first line of the input file. Each test case begins with a line containing a single integer number Nthat indicat

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值