编程介的小学生 2017-04-27 07:46 采纳率: 20.5%
浏览 805
已采纳

Mystery

Description

The Egyptian archeologists have found an old mysterious document that shows the secret key that should be used to open the main room of the largest pyramid. When the linguists translated the old documen t they found that they still have a problem to open the door, because the document itself is a puzzle whose solution will be the secret key. The old puzzle says that the key is consisted of some known integers and it shows the number of each integer in the key. It also mentions that there must be some pairs of letters in the key and the lexical order of the key must be as small as possible. A pair (x, y) of integers is considered to be in a key if there is a y coming after an x in the key. Your task is to help the archeologists to find the proper key.
Input

The input consists of several test cases. In the first line of each test case there are two integers m < 100 and d <= 1000, number of different integers in the key and number of given pairs, then in the next line there are m integers. The U+1th integer is the number of U's in the key . In the next d lines, in each line there is two integers x and y indicating that the pair ( x,y) is in the key. The test case with d=0 indicates the end o f file. If there is no solution for an input case you must report "Impossible!" as the output for this case.
Output

In the output, for each test case except the one with d=0 write the key in a separate line. Each two consecutive integers should be separated by exactly a single space.
Sample Input

3 2
1 0 2
2 0
2 2
0 0
Sample Output

2 0 2

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-04-27 07:59
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值