Vertex Cover
来源:互联网 发布:如何windows截屏 编辑:程序博客网 时间:2024/06/05 03:23
Vertex Cover
frog has a graph with
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
Output
For each test, write
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 <cstdio>#include <vector>#include <cstring>using namespace std;vector<int>map[505];bool vis[505];int conn[505];bool dfs(int x){ for(int i=0; i<map[x].size(); i++) { int y=map[x][i]; //printf("y=%d ",y); if(!vis[y]) { vis[y]=true; if(conn[y]==0||dfs(conn[y])) { conn[y]=x; conn[x]=y; return true; } } } return false;}int main(){ int n,m; while(~scanf("%d %d",&n,&m)) { memset(conn,0,sizeof(conn)); memset(map,0,sizeof(map)); for(int i=0; i<m; i++) { int a,b; scanf("%d %d",&a,&b); map[a].push_back(b); map[b].push_back(a); } int ans=0; for(int i=1; i<=n; i++) { if(!conn[i]){ memset(vis,false,sizeof(vis)); if(dfs(i)) ans++; } } printf("%d\n",ans); } return 0;}
阅读全文
0 0
- Vertex Cover
- Vertex Cover
- Vertex Cover
- set cover和vertex cover
- SPOJ 1435. Vertex Cover
- Vertex Cover问题
- vertex cover approximate algorithm
- SCU4439-Vertex Cover
- SCU-4439-Vertex Cover
- HDU6150 Vertex Cover
- 【HDU6150】Vertex Cover (构造)
- hdu 6150 Vertex Cover
- 1134. Vertex Cover (25)
- 1134. Vertex Cover (25)
- 1134. Vertex Cover (25)
- 1134. Vertex Cover (25)
- 1134. Vertex Cover (25)
- 1134. Vertex Cover (25)
- 大话设计模式之策略模式和工厂模式相结合
- Odoo 之parent_left 和 parent_right设计
- NMS——非极大值抑制
- mac homebrew 常用命令
- http://www.discuz.net/forum.php?mod=viewthread&tid=611716&page=1&authorid=13759
- Vertex Cover
- Android 7.0 java.lang.SecurityException: MODE_WORLD_READABLE no longer supported闪退
- webstorm 2016.3激活
- POJ 3096
- Hbase基础
- JS判断微信扫码的方法
- CentOS7.3中Tomcat8启动出错问题
- EasyStream系列3之rtsp转rtsp
- C 和 C++的对比