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 ...
随机推荐
- 快速搭建rabbitmq单节点并配置使用
安装erlang环境 wget http://erlang.org/download/otp_src_20.3.tar.gz tar xf otp_src_20.3.tar.gz && ...
- WebDriver中如何处理Iframe 及 嵌套Iframe
最近在用webdriver进行爬虫的时候,遇到了网站存在iframe的情况,处理了好久没有解决,后来发现原来webdriver自带处理方法,汗颜.. 1.iFrame有ID 或者 name的情况 // ...
- 省队集训 Day1 残缺的字符串
[题目大意] 双串带通配符匹配. $|S|, |T| \leq 5 * 10^5$ TL: 2s [题解] 参考bzoj 4503 可以设计如下函数 A[i] * B[i] * (A[i] - B[i ...
- jQuery操作Table学习总结[转]
<style type="text/css"> .hover { } </style>< ...
- 当你启动Redis的时候,Redis做了什么
直奔主题,当启动Redis的时候,Redis执行了哪些操作? 假设Redis安装在了/usr/local/目录下,那么启动Redis是通过执行/usr/local/bin/redis-server - ...
- [bzoj3993][SDOI2015]星际战争-二分+最大流
Brief Description 3333年,在银河系的某星球上,X军团和Y军团正在激烈地作战.在战斗的某一阶段,Y军团一共派遣了N个巨型机器人进攻X军团的阵地,其中第i个巨型机器人的装甲值为Ai. ...
- 20151024_002_C#基础知识(ArrayList,Hashtable,List,Dictionary)
1:ArrayList 和 Hashtable(哈希表) 1.1:ArrayList ArrayList list = new ArrayList(); list.Add(); list.AddRan ...
- js_微信分享,监听点击分享,分享成功,取消分享,分享失败回调
2017-06-13 见代码: function weixinShare() { var links = links = "www.youku.com"; common.get_o ...
- POJ1014(多重背包)
Dividing Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 65044 Accepted: 16884 Descri ...
- 测试mysqldump 压缩率和时间消耗
测试mysqldump 压缩率和时间消耗 实验总结: 从本次实验数据可以看出,mysqldump通过|gzip参数可以将导出文件压缩53%,同时耗时也普通非压缩模式的2.3倍. 数据库环境: #[ro ...