每日一题(01.01)

Description

平面上有一组点,它们之间有若干条线段相连。现在请你找到一个集合,使得在这个集合中没有任意两个点被线段相连。你只需要给出最大集合的元素即可。

Input

多行输入,第一行一个数N,表示有N个点,之后的N行每行以这样的形式给出:

点的标号: (与这个点相连的点的个数) 点的标号 点的标号……

或者

点的标号: (0)

当输入的N为0时退出程序。详见Sample。

Output

最大集合的元素个数。

Sample Input

7
0: (3) 4 5 6
1: (2) 4 6
2: (0)
3: (0)
4: (2) 0 1
5: (1) 0
6: (2) 0 1
3
0: (2) 1 2
1: (1) 0
2: (1) 0
0

Sample Output

5
2

Reference code

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
const int N=503;
int e[N][N],match[N],n;
int book[N];

int dfs(int u){
    for(int i=0;i<n;i++){
        if(book[i]==0 && e[u][i]==1){
            book[i]=1;
            if(match[i]==-1 || dfs(match[i])){
                match[i]=u;
                return 1;
            }
        }
    }
    return 0;
}

int main(){
    while(~scanf("%d",&n)){
        memset(e,0,sizeof e);
        memset(match,-1,sizeof match);
        for(int i=0;i<n;i++){
            int k,cnt;
            scanf("%d: (%d)",&k,&cnt);
            for(int j=0;j<cnt;j++){
                int x;
                scanf("%d",&x);
                e[i][x]=1;
            }
        }
        int ans=0;
        for(int i=0;i<n;i++){
            memset(book,0,sizeof(book));
            if(dfs(i))
				ans++;
        }
        printf("%d\n",n-ans/2);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值