首页 技术 正文
技术 2022年11月20日
0 收藏 549 点赞 4,973 浏览 1438 个字

Vertex Cover

frog has a graph with nn vertices v(1),v(2),…,v(n)v(1),v(2),…,v(n) and mm edges (v(a1),v(b1)),(v(a2),v(b2)),…,(v(am),v(bm))(v(a1),v(b1)),(v(a2),v(b2)),…,(v(am),v(bm)).

She would like to color some vertices so that each edge has at least one colored vertex.

Find the minimum number of colored vertices.

Input

The input consists of multiple tests. For each test:

The first line contains 22 integers n,mn,m (2≤n≤500,1≤m≤n(n−1)22≤n≤500,1≤m≤n(n−1)2). Each of the following mm lines contains 22 integers ai,biai,bi (1≤ai,bi≤n,ai≠bi,min{ai,bi}≤301≤ai,bi≤n,ai≠bi,min{ai,bi}≤30)

Output

For each test, write 11 integer which denotes the minimum number of colored vertices.

Sample Input

    3 2
1 2
1 3
6 5
1 2
1 3
1 4
2 5
2 6

Sample Output

    1
2

题意:有n个点m条边,每条边至少有一个顶点染色,至少要染多少个点

思路:二分图最小点覆盖,有一个公式 二分图最大匹配=最小点覆盖,匈牙利算法一代就出来了

#include<cstdio>
#include<string.h>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<deque>
using namespace std;
#define ll unsigned long long
vector<int>v[];
int match[];
bool used[];
bool dfs(int x)
{
used[x]=;//标记询问过了
for(int i=;i<v[x].size();i++)
{
int y=v[x][i];
int w=match[y];
if(w<||!used[w]&&dfs(w))
{//如果它没有匹配过或者(没有问过而且可以找到其它)
match[x]=y;
match[y]=x;
return ;
}
}
return ;
}
int main()
{
int n,m;
while(cin>>n>>m)
{
for(int i=;i<=;i++) v[i].clear();
for(int i=;i<=m;i++)
{
int x,y;
cin>>x>>y;
v[x].push_back(y);
v[y].push_back(x);
}
int res=;
memset(match,-,sizeof(match));
for(int i=;i<=n;i++)
{
if(match[i]<)//还没匹配
{
memset(used,,sizeof(used));//每次都要初始化
if(dfs(i))
//如果能匹配
res++;
}
}
}
cout<<res<<endl;
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,999
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,511
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,357
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,140
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848