#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std; #define MAXN 150
int n; //十字路口的数量
int m; //路的个数
int map[MAXN][MAXN];
int x[MAXN], y[MAXN];
int mark[MAXN]; int search(int a)
{
for (int i = ; i <= n; i++)
{
if (map[a][i] && !mark[i])
{
mark[i] = ;
if (y[i] == || search(y[i]))
{
x[a] = i;
y[i] = a;
return a;
}
}
}
return ;
} int main()
{
int t;
scanf("%d", &t);
while (t--)
{
memset(map, , sizeof(map));
memset(mark, , sizeof(mark));
scanf("%d %d", &n, &m);
for (int i = ; i < m; i++)
{
int a, b;
scanf("%d %d", &a, &b);
if (map[a][b] == )
map[a][b] = ;
} int ans1 = ;
memset(x, , sizeof(x));
memset(y, , sizeof(y)); for (int i = ; i <= n; i++)
{
if (x[i] == )
{
memset(mark, , sizeof(mark));
if (search(i))
ans1++;
}
}
printf("%d\n", n - ans1);
}
//system("pause");
return ;
}

hdu1151 Air Raid 基础匈牙利的更多相关文章

  1. HDU1151 Air Raid —— 最小路径覆盖

    题目链接:https://vjudge.net/problem/HDU-1151 Air Raid Time Limit: 2000/1000 MS (Java/Others)    Memory L ...

  2. Hdu1151 Air Raid(最小覆盖路径)

    Air Raid Problem Description Consider a town where all the streets are one-way and each street leads ...

  3. hdu1151 Air Raid

    http://acm.hdu.edu.cn/showproblem.php?pid=1151 增广路的变种2:DAG图的最小路径覆盖=定点数-最大匹配数 #include<iostream> ...

  4. hdu1151 Air Raid,DAG图的最小路径覆盖

    点击打开链接 有向无环图的最小路径覆盖 = 顶点数- 最大匹配 #include <queue> #include <cstdio> #include <cstring& ...

  5. hdu1151 Air Raid 二分匹配

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1151 求最小路径覆盖 二分图最小路径覆盖=点的个数-最大匹配. 代码: #include<ios ...

  6. Air Raid[HDU1151]

    Air RaidTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  7. hdu1151 二分图(无回路有向图)的最小路径覆盖 Air Raid

    欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Air Raid Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...

  8. HDU1151:Air Raid(最小边覆盖)

    Air Raid Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  9. 【网络流24题----03】Air Raid最小路径覆盖

    Air Raid Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

随机推荐

  1. this that 时间戳转日期 小程序 列表 与 加载

    var gd = getApp().globalData; var imgUrlApp = gd.imgUrlApp; var localImgPath = gd.localImgPath; var ...

  2. Studio 3T for MongoDB连接51.212复制集

    Studio 3T for MongoDB连接51.212复制集 [ #DirectConection Authentication Mode - Basic(MONGODB-CR or SCEAM- ...

  3. locate和grep命令

    这任然是一篇读书笔记,以下内容来源<linux命令速查手册>这本书. 1.locate命令 用文件名或者文件名的部分来搜索文件在系统中的位置.locate不搜索具体目录,而是搜索一个数据库 ...

  4. oracle服务丢失的处理方法之OracleServiceORCL不存在示例

    oracle服务是oracle数据库的重要组成部分,下面就教您oracle服务丢失的处理方法,如果您之前遇到过oracle服务丢失的问题,不妨一看. 今天发现数据库服务器上的所有oracle服务都丢失 ...

  5. redis.Pool 配置

    http://blog.csdn.net/xiaohu50/article/details/51606349

  6. mysql优化-------Myisam与innodb引擎,索引文件的区别

    Myisam与innodb引擎,索引文件的区别: innodb的次索引指向对主键的引用. myisam的次索引和主索引都指向物理行. myisam一行一行的插入,会产生一行一行的文件,磁盘上有数据文件 ...

  7. NEU 1683: H-Index

    题目描述 Given an array of citations (each citation is a non-negative integer) of a researcher, write a ...

  8. 获取cookies的简单代码(总结待续)

    Cookie[] cookies = request.getCookies(); Cookie cookie = null; for (int i = 0; i < cookies.length ...

  9. JAVA 单选样式编写

    <td class="main_matter_td">管网供水情况</td> <td align="left" class=&qu ...

  10. wcf中序列化BinaryFormatter,DataContractJsonSerializer,DataContractSerializer,SoapFormatter,XmlSerializer

    using System; using System.Runtime.Serialization; using System.Xml.Serialization; namespace Larryle. ...