编程介的小学生 2017-08-18 07:42 采纳率: 20.5%
浏览 770
已采纳

Archaeologist's Trouble

Lazy Genius recently received a detailed map of a tomb. He believed that there should be some rare relics in the tomb.

As known to all, there are many lethal traps in the tomb, certainly, including the entrance door. If you break into the tomb, you might be killed. Well, don't worry since you have a computer to help you. The door has N locks. Beside the door, there are M switches. Each switch controls several locks. When you press one switch, the corresponding locks will change their status (locked->unlocked, unlocked->locked). If any lock changes its status more than three times, all the locks will lock up and can't be unlocked forever.

Lazy wants to open the door as soon as possible. Because of your excellent accomplishment in the previous missions, Lazy turned to you, believing that you could help him.

Input

The input contains several test cases, separately by a blank line in-between.

The first line of each case contains two integers, N (0 < N < 30) and M (0 < M < 60). Then M lines follow. Each line begins with an integer k, and then followed by k integers that indicate the locks controlled by one switch.

Output

For each test case, output in one line the least number of switchs that should be pressed to open the door. If such a number does not exist, print "~~~~><~~~~".

Sample Input

4 3
3 1 2 3
2 3 4
1 4

Sample Output

2

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-08-18 15:34
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!