传送门

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),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 2 integers n,m (2≤n≤500,1≤m≤n(n−1)/2). Each of the following mm lines contains 2 integers ai,bi (1≤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<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = + ;
const int INF = <<;
vector <int> v[N];
int a[N];
bool vis[N];
bool dfs(int x) {
vis[x] = true;
for (int i = ; i < v[x].size(); i++) {
int y = v[x][i];
int z = a[y];
if (!z||(!vis[z]&&dfs(z))) {
a[x] = y;
a[y] = x;
return true;
}
}
return false;
}
int main() {
int n,m,x,y;
while (~scanf("%d%d",&n,&m)) {
for (int i = ; i <= n; i++) v[i].clear();
for (int i = ; i < m; i++) {
scanf("%d%d",&x,&y);
v[x].push_back(y);
v[y].push_back(x);
}
int ans = ;
memset(a,, sizeof(a));
for (int i = ; i <= n; i++) {
if (!a[i]) {
memset(vis,false, sizeof(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), \dots, v(n)\) and \(m\) edges \((v(a ...

  2. scu 4439 Vertex Cover

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

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

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

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

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

  5. 二分图匹配 + 最小点覆盖 - Vertex Cover

    Vertex Cover Problem's Link Mean: 给你一个无向图,让你给图中的结点染色,使得:每条边的两个顶点至少有一个顶点被染色.求最少的染色顶点数. analyse: 裸的最小点 ...

  6. 四川第七届 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), ...

  7. SCU - 4439 最小点覆盖

    题意:求最小的染色顶点数满足所有的边至少有个一端点被染色 2015四川省赛,过题数17/120+,还以为是什么难题,这不就是裸的二分图最小点覆盖吗.. 掏出了尘封一年的破板子 #include< ...

  8. URAL 2038 Minimum Vertex Cover

    2038. Minimum Vertex Cover Time limit: 1.0 secondMemory limit: 64 MB A vertex cover of a graph is a ...

  9. 集合覆盖 顶点覆盖: set cover和vertex cover

    这里将讲解一下npc问题中set cover和vertex cover分别是什么. set cover: 问题定义: 实例:现在有一个集合A,其中包含了m个元素(注意,集合是无序的,并且包含的元素也是 ...

随机推荐

  1. python新知识

    # 强制字符串转化 repr(1.1 + 2.2) # 字符串换行 a = "hello, world. " \ "it's a nice day. " \ & ...

  2. python NameError: name 'raw_input' is not defined

    错误:NameError: name 'raw_input' is not defined 原因出在raw_input ,python3.0版本后用input替换了raw_input 话说回来,学习p ...

  3. 模版——KMP

    #include <iostream> #include <cstdio> #include <cstring> ; int f[maxn]; char P[max ...

  4. 深度优先遍历 and 广度优先遍历

    深度优先遍历 and 广度优先遍历 遍历在前端的应用场景不多,多数是处理DOM节点数或者 深拷贝.下面笔者以深拷贝为例,简单说明一些这两种遍历.

  5. P1085 管家的忠诚

    题目描述 老管家是一个聪明能干的人.他为财主工作了整整10年,财主为了让自已账目更加清楚.要求管家每天记k次账,由于管家聪明能干,因而管家总是让财主十分满意.但是由于一些人的挑拨,财主还是对管家产生了 ...

  6. linux llseek 实现

    llseek 方法实现了 lseek 和 llseek 系统调用. 我们已经说了如果 llseek 方法从设备 的操作中缺失, 内核中的缺省的实现进行移位通过修改 filp->f_pos, 这是 ...

  7. C# 任务并行

    . List<int> ids = new List<int>(); ; i < ; i++) { ids.Add(i); } ;//最大并行数量 List<Tas ...

  8. Linux 内核驱动结构嵌入

    如同大部分驱动核心结构的情形, device_driver 结构常常被发现嵌到一个更高级的, 总 线特定的结构. lddbus 子系统不会和这样的趋势相反, 因此它已定义了它自己的 ldd_drive ...

  9. vue-learning:9-template-v-model

    表单元素的双向绑定指令v-model 目录 v-model的基础用法 v-model双向绑定实现的原理 v-model绑定值的输出类型(字符串.数组.布尔值.自定义) v-model修饰符:.lazy ...

  10. 5.29 SD省队培训D1

    5.29 SD省队培训D1 自闭的一天 T1 梦批糼 先咕一咕(两天之内一定补上) T2 等你哈苏德 继续咕(一星期之内补上) T3喜欢最最痛 四十分做法: 首先,我们发现同一个点加两条额外边是一件非 ...