300930: CF177C2. Party

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Party

题意翻译

Beaver 有 $n$ 个熟人,这些人之间有若干个朋友关系与讨厌关系。现在,Beaver 想邀请他们去一个派对 当然,对于去派对的人是有要求的。 对于每一个去派对的人: - 他的所有朋友的应该在派对中,不管是直接朋友还是间接朋友 - 派对里不应该有他讨厌的人 你的任务是求出 Beaver 可以邀请的最多的人数 ### 输入格式 第一行一个整数 $n$,表示 Beaver 的熟人的个数 第二行一个整数 $k$,表示朋友关系的个数 接下来 $k$ 行,每行两个整数表示一对朋友 接下来一行一个整数 $m$,表示讨厌关系的个数 接下来 $m$ 行,每行两个整数表示一对互相讨厌的人 ### 输出格式 一行一个整数,表示最多能邀请的人的个数 如果一个人都邀请不了,则输出 $0$ **说明与提示** $n \le 2000$ $0 \le k,m \le min(10^5, \frac{n\cdot (n-1)}{2})$ $0 \le k+m \le min(10^5, \frac{n\cdot (n-1)}{2})$ 感谢 @[_Wolverine](https://www.luogu.com.cn/user/120362) 提供的翻译

题目描述

To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friendship relations, and not to invite those who dislike each other. Both friendship and dislike are mutual feelings. More formally, for each invited person the following conditions should be fulfilled: - all his friends should also be invited to the party; - the party shouldn't have any people he dislikes; - all people who are invited to the party should be connected with him by friendship either directly or through a chain of common friends of arbitrary length. We'll say that people $ a_{1} $ and $ a_{p} $ are connected through a chain of common friends if there exists a sequence of people $ a_{2},a_{3},...,a_{p-1} $ such that all pairs of people $ a_{i} $ and $ a_{i+1} $ ( $ 1<=i<p $ ) are friends. Help the Beaver find the maximum number of acquaintances he can invite.

输入输出格式

输入格式


The first line of input contains an integer $ n $ — the number of the Beaver's acquaintances. The second line contains an integer $ k $ ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF177C2/27889a033194c453412ceaf5264842611777ac84.png) — the number of pairs of friends. Next $ k $ lines contain space-separated pairs of integers $ u_{i},v_{i} $ ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF177C2/10f0e33bfed644df18cefd5704b1b80a21445141.png) — indices of people who form the $ i $ -th pair of friends. The next line contains an integer $ m $ ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF177C2/b31daf7410b0aad3f01ccae68177a765032fdaa0.png) — the number of pairs of people who dislike each other. Next $ m $ lines describe pairs of people who dislike each other in the same format as the pairs of friends were described. Each pair of people is mentioned in the input at most once ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF177C2/b930b1fd6e52f0ddc42e6d834d14499ffcfa3bac.png). In particular, two persons cannot be friends and dislike each other at the same time. The input limitations for getting 30 points are: - $ 2<=n<=14 $ The input limitations for getting 100 points are: - $ 2<=n<=2000 $

输出格式


Output a single number — the maximum number of people that can be invited to the party. If a group of people that meets all the requirements is impossible to select, output 0.

输入输出样例

输入样例 #1

9
8
1 2
1 3
2 3
4 5
6 7
7 8
8 9
9 6
2
1 6
7 9

输出样例 #1

3

说明

Let's have a look at the example. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF177C2/2a1afae751aa0d8fbeb2d7b54cbbe0f7e8bfc3ce.png)Two groups of people can be invited: $ {1,2,3} $ and $ {4,5} $ , thus the answer will be the size of the largest of these groups. Group $ {6,7,8,9} $ doesn't fit, since it includes people $ 7 $ and $ 9 $ who dislike each other. Group $ {1,2,3,4,5} $ also doesn't fit, because not all of its members are connected by a chain of common friends (for example, people $ 2 $ and $ 5 $ aren't connected).

Input

题意翻译

Beaver 有 $n$ 个熟人,这些人之间有若干个朋友关系与讨厌关系。现在,Beaver 想邀请他们去一个派对 当然,对于去派对的人是有要求的。 对于每一个去派对的人: - 他的所有朋友的应该在派对中,不管是直接朋友还是间接朋友 - 派对里不应该有他讨厌的人 你的任务是求出 Beaver 可以邀请的最多的人数 ### 输入格式 第一行一个整数 $n$,表示 Beaver 的熟人的个数 第二行一个整数 $k$,表示朋友关系的个数 接下来 $k$ 行,每行两个整数表示一对朋友 接下来一行一个整数 $m$,表示讨厌关系的个数 接下来 $m$ 行,每行两个整数表示一对互相讨厌的人 ### 输出格式 一行一个整数,表示最多能邀请的人的个数 如果一个人都邀请不了,则输出 $0$ **说明与提示** $n \le 2000$ $0 \le k,m \le min(10^5, \frac{n\cdot (n-1)}{2})$ $0 \le k+m \le min(10^5, \frac{n\cdot (n-1)}{2})$ 感谢 @[_Wolverine](https://www.luogu.com.cn/user/120362) 提供的翻译

加入题单

上一题 下一题 算法标签: