Vertex Cover

frog has a graph with \(n\) vertices \(v(1), v(2), \dots, v(n)\) and \(m\) edges \((v(a_1), v(b_1)), (v(a_2), v(b_2)), \dots, (v(a_m), v(b_m))\).

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 \(2\) integers \(n, m\) (\(2 \leq n \leq 500, 1 \leq m \leq \frac{n(n - 1)}{2}\)). Each of the following \(m\) lines contains \(2\) integers \(a_i, b_i\) (\(1 \leq a_i, b_i \leq n, a_i \neq b_i, \min\{a_i, b_i\} \leq 30\))

Output

For each test, write \(1\) 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
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define met(a,b) memset(a,b,sizeof a)
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
const int N = 1e5+;
const double eps = 1e-;
int T,n,cnt,m;
bool ok=true;
int k,mi[N];
int a[N],vis[N],match[N];
char str[N],s[N];
vector<int>edg[N];
bool dfs(int now){
for(int i=;i<edg[now].size();++i){
int x=edg[now][i];
if(!vis[x]){
vis[x]=;
if(!match[x]||dfs(match[x])){
match[now]=x;
match[x]=now;
return true;
}
}
}
return false;
}
int main()
{
int u,v;
while(~scanf("%d%d",&n,&m)){
for(int i=;i<N;i++)edg[i].clear(),match[i]=;
int ans=;
while(m--){
scanf("%d%d",&u,&v);
edg[u].pb(v);
edg[v].pb(u);
}
for(int i=;i<=n;i++){
if(!match[i]){
met(vis,);
if(dfs(i))ans++;
}
}
printf("%d\n",ans);
}
return ;
}
 

SCU - 4439 Vertex Cover (图的最小点覆盖集)的更多相关文章

  1. SCU 4439 Vertex Cover|最小点覆盖

    传送门 Vertex Cover frog has a graph with n vertices v(1),v(2),…,v(n)v(1),v(2),…,v(n) and m edges (v(a1 ...

  2. 四川第七届 D Vertex Cover(二分图最小点覆盖,二分匹配模板)

    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), ...

  3. scu 4439 Vertex Cover

    题意: 给出n个点,m条边,将若干个点染色,使得每个边至少有一点染色,问至少染多少个点. 思路: 如果是二分图,那就是最小点覆盖,但是这是一般图. 一般图的最小覆盖是npc问题,但是这题有一个条件比较 ...

  4. SCU 4439 Vertex Cover(二分图最小覆盖点)题解

    题意:每一条边至少有一个端点要涂颜色,问最少涂几个点 思路:最小顶点覆盖:用最少的点,让每条边都至少和其中一个点关联,显然是道裸最小顶点覆盖题: 参考:二分图 代码: #include<iost ...

  5. 第十五届四川省省赛 SCU - 4439 Vertex Cover

    给你一个一般图 保证每条边的一端下标不大于30 问最小覆盖集的大小为多少 爆搜:枚举前30个点是否在覆盖集内 剪枝1:如果不在的话 那么他所连的下标大于30的点都必须选 剪纸2:最优解剪枝 #incl ...

  6. Jewelry Exhibition(最小点覆盖集)

    Jewelry Exhibition 时间限制: 1 Sec  内存限制: 64 MB提交: 3  解决: 3[提交][状态][讨论版] 题目描述 To guard the art jewelry e ...

  7. 二分图变种之最小路径覆盖、最小点覆盖集【poj3041】【poj2060】

    [pixiv] https://www.pixiv.net/member_illust.php?mode=medium&illust_id=54859604 向大(hei)佬(e)势力学(di ...

  8. POJ 3041 Asteroids (二分图最小点覆盖集)

    Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 24789   Accepted: 13439 Descr ...

  9. ACM/ICPC 之 机器调度-匈牙利算法解最小点覆盖集(DFS)(POJ1325)

    //匈牙利算法-DFS //求最小点覆盖集 == 求最大匹配 //Time:0Ms Memory:208K #include<iostream> #include<cstring&g ...

随机推荐

  1. IntelliJ IDEA 热加载

    修改java文件后 win按:Ctrl+Shift+F9 mac按:cmd+Shift+F9 tomcat-maven-plugin 启动的项目也用这个快捷键热加载

  2. 【poj2104-求区间第k大数(不修改)】主席树/可持续化线段树

    第一道主席树~然而是道比较水的...因为它不用修改... 转载一个让我看懂的主席树的讲解吧:http://blog.csdn.net/regina8023/article/details/419106 ...

  3. Linux系统网络基础知识及配置

    一:DNS(domain name system)简介 DNS(Domain Name System,域名系统),因特网上作为域名和IP地址相互映射的一个分布式数据库,能够使用户更方便的访问互联网,而 ...

  4. Fire! (双bfs+预处理)

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  5. document的属性与方法小结

    document节点是文档的根节点,每张网页都有自己的document节点.属性:1:document.doctype----它是一个对象,包含了当前文档类型 (Document Type Decla ...

  6. JSP九大内置对象,七大动作,三大指令

    JSP之九大内置对象 隐藏对象入门探索 Servlet 和JSP中输出数据都需要使用out对象.Servlet 中的out对象是通过getWriter()方法获取的.而JSP中没有定义out对象却可以 ...

  7. Java的9种基本数据类型的大小,以及他们的封装类

    由于java程序是运行在虚拟机之上的,所以java的基本数据类型的大小是确定的,不会随着操作系统的位数的改变而改变. 在计算机中,存储的是0,1,0,1这样的二进制位,表示为bit,1Byte = 8 ...

  8. 【Python问题解决】关于解决python3.x无法使用PIL库的解决方法

    因为PIL库目前只更新到python2.x,故python3.x直接安装PIL库会找不到版本.但是python3.x有一个新的库,可以提供和PIL差不多的功能,也就是pillow库. 本人使用的是py ...

  9. LeetCode 20 Generate Parentheses

    Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...

  10. mysql查询语句的执行顺序(重点)

    一 SELECT语句关键字的定义顺序 SELECT DISTINCT <select_list> FROM <left_table> <join_type> JOI ...