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_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 (图的最小点覆盖集)的更多相关文章
- 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 ...
- 四川第七届 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), ...
- scu 4439 Vertex Cover
题意: 给出n个点,m条边,将若干个点染色,使得每个边至少有一点染色,问至少染多少个点. 思路: 如果是二分图,那就是最小点覆盖,但是这是一般图. 一般图的最小覆盖是npc问题,但是这题有一个条件比较 ...
- SCU 4439 Vertex Cover(二分图最小覆盖点)题解
题意:每一条边至少有一个端点要涂颜色,问最少涂几个点 思路:最小顶点覆盖:用最少的点,让每条边都至少和其中一个点关联,显然是道裸最小顶点覆盖题: 参考:二分图 代码: #include<iost ...
- 第十五届四川省省赛 SCU - 4439 Vertex Cover
给你一个一般图 保证每条边的一端下标不大于30 问最小覆盖集的大小为多少 爆搜:枚举前30个点是否在覆盖集内 剪枝1:如果不在的话 那么他所连的下标大于30的点都必须选 剪纸2:最优解剪枝 #incl ...
- Jewelry Exhibition(最小点覆盖集)
Jewelry Exhibition 时间限制: 1 Sec 内存限制: 64 MB提交: 3 解决: 3[提交][状态][讨论版] 题目描述 To guard the art jewelry e ...
- 二分图变种之最小路径覆盖、最小点覆盖集【poj3041】【poj2060】
[pixiv] https://www.pixiv.net/member_illust.php?mode=medium&illust_id=54859604 向大(hei)佬(e)势力学(di ...
- POJ 3041 Asteroids (二分图最小点覆盖集)
Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 24789 Accepted: 13439 Descr ...
- ACM/ICPC 之 机器调度-匈牙利算法解最小点覆盖集(DFS)(POJ1325)
//匈牙利算法-DFS //求最小点覆盖集 == 求最大匹配 //Time:0Ms Memory:208K #include<iostream> #include<cstring&g ...
随机推荐
- 2015/9/18 Python基础(14):函数式编程
这篇写了忘发.现在补上. Python不是也不大可能成为一种函数式的编程语言,但是它支持许多有价值的函数式编程语言构建.也有些表现的像函数式编程机制但是从传统上也不能认为是函数式编程语言的构建.Pyt ...
- JDK工具学习
javap: 可以对照源代码和字节码,从而了解很多编译器内部的工作. 查看class字节码:JDK有自带的工具包,使用javap命令打开.class文件就行 javap -c JAVAPTest
- 【BZOJ5010】【FJOI2017】矩阵填数 [状压DP]
矩阵填数 Time Limit: 10 Sec Memory Limit: 128 MB[Submit][Status][Discuss] Description 给定一个 h*w 的矩阵,矩阵的行 ...
- loj515 「LibreOJ β Round #2」贪心只能过样例
传送门:https://loj.ac/problem/515 [题解] 容易发现S最大到1000000. 于是我们有一个$O(n^2*S)$的dp做法. 容易发现可以被bitset优化. 于是复杂度就 ...
- 「6月雅礼集训 2017 Day11」jump
[题目大意] 有$n$个位置,每个位置有一个数$x_i$,代表从$i$经过1步可以到达的点在$[\max(1, i-x_i), \min(i+x_i, n)]$中. 定义$(i,j)$的距离表示从$i ...
- 多线程---iOS-Apple苹果官方文档翻译
本系列所有开发文档翻译链接地址:iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译PDF下载地址(2013年12月29日更新版) 多线程 技术博客http://www.cnblo ...
- 函数getopt()及其参数optind -- (转)
getopt被用来解析命令行选项参数 #include <unistd.h> extern char *optarg; //选项的参数指针 extern int ...
- 【转】ps命令详解
原文地址:http://apps.hi.baidu.com/share/detail/32573968 有 时候系统管理员可能只关心现在系统中运行着哪些程序,而不想知道有哪些进程在运行.由于一个应用程 ...
- perl HTML::LinkExtor模块(2)
use LWP::Simple; use HTML::LinkExtor; $html_code = get("https://tieba.baidu.com/p/4929234512&qu ...
- 深入分析_linux_spinlock_实现机制【转】
转自:http://blog.csdn.net/electrombile/article/details/51289813 在 x86 平台上,spinlock 主要通过处理器的 lock 指令前缀实 ...