HDOJ1150(最小点集覆盖)
2024-09-29 07:00:29
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector> using namespace std; #define N 101 int match[N];
bool vis[N];
vector <int> e[N];
int n, m, k; void InitRead(); void DataProcess(); bool Dfs(int x); int main()
{
while (~scanf("%d", &n))
{
if (n == 0) break;
InitRead();
DataProcess();
}
return 0;
} void InitRead()
{
scanf("%d %d", &m, &k);
memset(match, -1, sizeof(match));
for (int i=0; i<N; ++i) e[i].clear();
int a, b;
for (int i=0; i<k; ++i)
{
scanf("%*d %d %d", &a, &b);
if (a == 0 || b == 0) continue; //可以用模式0解决的任务不建边
e[a].push_back(b);
}
return;
} void DataProcess()
{
int ans = 0;
for (int i=0; i<n; ++i)
{
memset(vis, false, sizeof(vis));
if (Dfs(i)) ans++;
}
printf("%d\n", ans);
return;
} bool Dfs(int x)
{
int size = e[x].size();
for (int i=0; i<size; ++i)
{
if (!vis[e[x][i]])
{
vis[e[x][i]] = true;
if (match[e[x][i]] == -1 || Dfs(match[e[x][i]]))
{
match[e[x][i]] = x;
return true;
}
}
}
return false;
}
最新文章
- 任务调度框架-Quartz.Net
- ExtJs TreePanel 使用帮助
- a++ ++a 文件上传函数错误 smarty模板特点
- Android应用集成支付宝接口的简化
- Fedora安装
- var foo= {} ;foo.method() 和 单例模式有什么区别
- HTML标签CSS属性默认值汇总
- MySQL存储引擎差异化实验
- <;验证码的产生>;C语言---验证码的产生和验证
- 单例设计模式 Single
- 查看Zookeeper服务器状态信息的一些命令
- python Http协议
- ABP入门系列(1)——通过模板创建MAP版本项目
- Chrome浏览器添加控件
- Codeforces Round #442 (Div. 2) E Danil and a Part-time Job (dfs序加上一个线段树区间修改查询)
- Java实现三大简单排序算法
- php 日期和时间
- mysql时间函数和时间操作
- 基于MINA实现server端心跳检测(KeepAliveFilter)
- awk处理excel表格数据