Ratish is a young man who always dreams of being a hero. One day his friend Luffy was caught by Pirate Arlong. Ratish set off at once to Arlong's island. When he got there, he found the secret place where his friend was kept, but he could not go straight in. He saw a large door in front of him and two locks in the door. Beside the large door, he found a strange rock, on which there were some odd words. The sentences were encrypted. But that was easy for Ratish, an amateur cryptographer. After decrypting all the sentences, Ratish knew the following facts:
Behind the large door, there is a nesting prison, which consists of M floors. Each floor except the deepest one has a door leading to the next floor, and there are two locks in each of these doors. Ratish can pass through a door if he opens either of the two locks in it. There are 2N different types of locks in all. The same type of locks may appear in different doors, and a door may have two locks of the same type. There is only one key that can unlock one type of lock, so there are 2N keys for all the 2N types of locks. These 2N keys were made N pairs,one key may be appear in some pairs, and once one key in a pair is used, the other key will disappear and never show up again.
Later, Ratish found N pairs of keys under the rock and a piece of paper recording exactly what kinds of locks are in the M doors. But Ratish doesn't know which floor Luffy is held, so he has to open as many doors as possible. Can you help him to choose N keys to open the maximum number of doors?
There are several test cases. Every test case starts with a line containing two positive integers N (1 <= N <= 2^10) and M (1 <= M <= 2^11) separated by a space, the first integer represents the number of types of keys and the second integer represents the number of doors. The 2N keys are numbered 0, 1, 2, ..., 2N - 1. Each of the following N lines contains two integers, which are the numbers of two keys in a pair. After that, each of the following M lines contains two integers, which are the numbers of two keys corresponding to the two locks in a door. You should note that the doors are given in the same order that Ratish will meet. A test case with N = M = 0 ends the input, and should not be processed.
For each test case, output one line containing an integer, which is the maximum number of doors Ratish can open.
- 博客 在中国程序员是青春饭吗？
- 博客 程序员请照顾好自己，周末病魔差点一套带走我。
- 博客 和黑客斗争的 6 天！
- 博客 点沙成金：英特尔芯片制造全过程揭密
- 博客 上班一个月，后悔当初着急入职的选择了
- 博客 女程序员，为什么比男程序员少？？？
- 博客 副业收入是我做程序媛的3倍，工作外的B面人生是怎样的？
- 博客 如果你是老板，你会不会踢了这样的员工？
- 博客 我入职阿里后，才知道原来简历这么写
- 博客 外包程序员的幸福生活
- 博客 C++11：一些微小的变化（新的数据类型、template表达式内的空格、nullptr、std::nullptr_t）
- 博客 优雅的替换if-else语句
- 博客 深入剖析Springboot启动原理的底层源码，再也不怕面试官问了！
- 博客 离职半年了，老东家又发 offer，回不回？
- 博客 为什么你不想学习？只想玩？人是如何一步一步废掉的
- 博客 为什么程序员做外包会被瞧不起？
- 博客 当HR压你价，说你只值7K，你该怎么回答？
- 博客 面试：第十六章：Java中级开发（16k）
- 博客 面试阿里p7，被按在地上摩擦，鬼知道我经历了什么？
- 博客 面试了一个 31 岁程序员，让我有所触动，30岁以上的程序员该何去何从？
- 博客 【阿里P6面经】二本，curd两年，疯狂复习，拿下阿里offer
- 博客 大三实习生，字节跳动面经分享，已拿Offer
- 博客 程序员垃圾简历长什么样？
- 博客 《经典算法案例》01-08：如何使用质数设计扫雷（Minesweeper）游戏
- 博客 《Oracle Java SE编程自学与面试指南》最佳学习路线图（2020最新版）
- 博客 面试官：你连SSO都不懂，就别来面试了
- 博客 微软为一人收购一公司？破解索尼程序、写黑客小说，看他彪悍的程序人生！...
- 博客 终于，月薪过5万了！
- 博客 我说我懂多线程，面试官立马给我发了offer
- 博客 自从喜欢上了B站这12个UP主，我越来越觉得自己是个废柴了！