poj 1422 Air Raid(最小不相交路径覆盖)
来源:互联网 发布:海洋cms一点不好用 编辑:程序博客网 时间:2024/05/21 20:21
最小不相交路径覆盖 = 顶点数 - 最大匹配
#include <cstdio>#include <vector>#include <queue>using namespace std;typedef long long LL;const int MAXN = 120+5;const int inf = 1e9;int n,m;vector<int>head[MAXN];bool vis[MAXN];int match[MAXN];bool dfs(int u){ for(int i = 0,l = head[u].size(); i < l; ++i) { int v = head[u][i]; if(!vis[v]) { vis[v] = 1; if(match[v] == -1 || dfs(match[v])) { match[v] = u; return 1; } } } return 0;}int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); int u,v; for(int i = 1; i <= n; ++i)head[i].clear(); while(m--) { scanf("%d%d",&u,&v); head[u].push_back(v); } fill(match+1,match+1+n,-1); int ans = n; for(int i = 1; i <= n; ++i) { fill(vis+1,vis+1+n,0); if(dfs(i))ans--; } printf("%d\n",ans); } return 0;}
阅读全文
1 0
- poj 1422 Air Raid(最小不相交路径覆盖)
- poj 1422 Air Raid (二分图+有向图最小不相交路径覆盖)
- [POJ]1422-Air Raid(最小路径覆盖)
- poj 1422Air Raid--最小路径覆盖
- poj 1422 Air Raid 最小路径覆盖
- poj 1422 Air Raid(最小路径覆盖)
- poj 1422 Air Raid(最小路径覆盖)
- poj 1422 Air Raid(最小路径覆盖)
- poj 1422 Air Raid (最小路径覆盖)
- poj 1422&&HDU 1151 Air Raid(最小路径覆盖)
- POJ 1422 Air Raid (最小路径覆盖)
- POJ 1422 && ZOJ 1525 Air Raid(最小路径覆盖)
- poj 1422 Air Raid (最小路径覆盖白痴题)
- POJ-1422 Air Raid 最小路径覆盖模板题
- POJ 1422 Air Raid(匈牙利算法—最小路径覆盖)
- POJ-1422-Air Raid (二分图 最小路径覆盖)
- POJ 1422 Air Raid(DAG最小路径覆盖)
- 【二分图|最小路径覆盖】POJ-1422 Air Raid
- 野指针
- grep 命令
- angularJS-实现放大镜效果
- SVM问题形式化
- VBA-周次表示Format
- poj 1422 Air Raid(最小不相交路径覆盖)
- Java笔记--04
- matlab将矩阵化成行最简形
- Sqoop 简介及安装部署
- 中国大学MOOC·Python网络爬虫与信息提取(一)
- C#笔记(5)textbox的hint属性
- 爬虫实战12—自动摘要及正文抽取
- JavaWeb Session 之表单的重复提交
- Mycat概述