HDU 1054 Strategic Game
来源:互联网 发布:企业无线覆盖 知乎 编辑:程序博客网 时间:2024/06/05 10:13
题意:给定一个图每一个点能够观察到相邻的所有点,问最少需要多少个顶点就能够覆盖整个图。
思路:最小顶点覆盖问题,很基础,直接建图求最大匹配然后/2得答案,二分图的最小顶点覆盖直接就是最大匹配数。
#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#include <cstdlib>#include <queue>using namespace std;struct node{ int v; int next;}d[1000000];int head[2500];int vis[2500];int pre[2500];int cnt;void add(int x,int y){ d[cnt].v=y; d[cnt].next=head[x]; head[x]=cnt++;}int dfs(int u){ for(int i=head[u];i!=-1;i=d[i].next) { int v=d[i].v; if(!vis[v]) { vis[v]=1; if(pre[v]==-1||dfs(pre[v])) { pre[v]=u; return 1; } } } return 0;}int main(){ int n,x,y,m; while(~scanf("%d",&n)) { memset(head,-1,sizeof(head)); memset(pre,-1,sizeof(pre)); cnt=0; int ans=0; for(int i=0;i<n;i++) { scanf("%d:(%d)",&x,&m); for(int j=0;j<m;j++) { scanf("%d",&y); add(x,y); add(y,x); } } for(int i=0;i<n;i++) { memset(vis,0,sizeof(vis)); ans += dfs(i); } printf("%d\n",ans/2); } return 0;}
0 0
- hdu 1054 Strategic Game
- HDU 1054 Strategic Game
- hdu 1054 Strategic Game
- hdu 1054 Strategic Game
- Hdu 1054 Strategic Game
- hdu 1054 Strategic Game
- HDU - 1054 Strategic Game
- hdu 1054 Strategic Game
- hdu-1054-Strategic Game
- HDU 1054 Strategic Game
- HDU 1054 Strategic Game
- HDU 1054 Strategic Game
- HDU 1054:Strategic Game
- HDU 1054 Strategic Game
- HDU 1054 Strategic Game
- HDU 1054Strategic Game 贪心
- hdu/hdoj 1054 Strategic Game
- hdu 1054 Strategic Game (二分匹配)
- 关于智能机器人
- 针对Alexa Top 100站点进行的一次钓鱼攻击分析
- Python学习笔记(二)——语法
- JVM分代垃圾回收策略的基础概念
- iOS 复习题
- HDU 1054 Strategic Game
- HTML5新增的属性和废除的属性
- Antivirus and Hyper-V (or: Why can’t I start my virtual machine?)
- windows server相关
- iOS 复习题
- android开发练习二-Retrofit
- 为什么要使用Fragment!
- Oracle 一些常用函数
- php中的&