题目链接:

http://poj.org/problem?id=1422

Description

Consider a town where all the streets are one-way and each street leads from one intersection to another. It is also known that starting from an intersection and walking through town's streets you can never reach the same intersection i.e. the town's streets form no cycles.

With these assumptions your task is to write a program that finds the minimum number of paratroopers that can descend on the town and visit all the intersections of this town in such a way that more than one paratrooper visits no intersection. Each paratrooper lands at an intersection and can visit other intersections following the town streets. There are no restrictions about the starting intersection for each paratrooper. 

Input

Your program should read sets of data. The first line of the input file contains the number of the data sets. Each data set specifies the structure of a town and has the format:

no_of_intersections 
no_of_streets 
S1 E1 
S2 E2 
...... 
Sno_of_streets Eno_of_streets

The first line of each data set contains a positive integer no_of_intersections (greater than 0 and less or equal to 120), which is the number of intersections in the town. The second line contains a positive integer no_of_streets, which is the number of streets in the town. The next no_of_streets lines, one for each street in the town, are randomly ordered and represent the town's streets. The line corresponding to street k (k <= no_of_streets) consists of two positive integers, separated by one blank: Sk (1 <= Sk <= no_of_intersections) - the number of the intersection that is the start of the street, and Ek (1 <= Ek <= no_of_intersections) - the number of the intersection that is the end of the street. Intersections are represented by integers from 1 to no_of_intersections.

There are no blank lines between consecutive sets of data. Input data are correct. 

Output

The result of the program is on standard output. For each input data set the program prints on a single line, starting from the beginning of the line, one integer: the minimum number of paratroopers required to visit all the intersections in the town. 

Sample Input

2
4
3
3 4
1 3
2 3
3
3
1 3
1 2
2 3

Sample Output

2
1
题意描述:
输入村庄的个数以及哪两个村庄有道路,有向图,无回路,问每条路只能被走一次,最少需要几个伞兵。
解题思路:
问题是求每条路只能走一次,问最少需要几个伞兵能将这几个村庄全部走完,那么求的是最小路径覆盖数,为什么不是最小顶点覆盖呢,因为求顶点只会到达点,而此题求到达点都还能沿着路访问其他顶点,故求的是最小路径覆盖。
AC代码:
 #include<stdio.h>
#include<string.h>
int maxmatch();
int path(int u);
int n,m,e[][],match[],book[];
int main()
{
int T,i,j;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
memset(e,,sizeof(e));
while(m--)
{
scanf("%d%d",&i,&j);
e[i][j]=;
}
printf("%d\n",n-maxmatch());
}
return ;
}
int maxmatch()
{
int i,res=;
memset(match,,sizeof(match));
for(i=;i<=n;i++)
{
memset(book,,sizeof(book));
res += path(i);
}
return res;
}
int path(int u)
{
int i;
for(i=;i<=n;i++)
{
if(e[u][i] && !book[i])
{
book[i]=;
if(!match[i] || path(match[i]))
{
match[i]=u;
return ;
}
}
}
return ;
}

POJ 1422 Air Raid的更多相关文章

  1. POJ 1422 Air Raid(二分图匹配最小路径覆盖)

    POJ 1422 Air Raid 题目链接 题意:给定一个有向图,在这个图上的某些点上放伞兵,能够使伞兵能够走到图上全部的点.且每一个点仅仅被一个伞兵走一次.问至少放多少伞兵 思路:二分图的最小路径 ...

  2. poj 1422 Air Raid (二分匹配)

    Air Raid Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6520   Accepted: 3877 Descript ...

  3. poj——1422 Air Raid

    Air Raid Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8577   Accepted: 5127 Descript ...

  4. poj 1422 Air Raid 最少路径覆盖

    题目链接:http://poj.org/problem?id=1422 Consider a town where all the streets are one-way and each stree ...

  5. POJ 1422 Air Raid (最小路径覆盖)

    题意 给定一个有向图,在这个图上的某些点上放伞兵,可以使伞兵可以走到图上所有的点.且每个点只被一个伞兵走一次.问至少放多少伞兵. 思路 裸的最小路径覆盖. °最小路径覆盖 [路径覆盖]在一个有向图G( ...

  6. POJ - 1422 Air Raid 二分图最大匹配

    题目大意:有n个点,m条单向线段.如今问要从几个点出发才干遍历到全部的点 解题思路:二分图最大匹配,仅仅要一条匹配,就表示两个点联通,两个点联通仅仅须要选取当中一个点就可以,所以有多少条匹配.就能够减 ...

  7. POJ - 1422 Air Raid(DAG的最小路径覆盖数)

    1.一个有向无环图(DAG),M个点,K条有向边,求DAG的最小路径覆盖数 2.DAG的最小路径覆盖数=DAG图中的节点数-相应二分图中的最大匹配数 3. /* 顶点编号从0开始的 邻接矩阵(匈牙利算 ...

  8. POJ——T 1422 Air Raid

    http://poj.org/problem?id=1422 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8579   A ...

  9. POJ 1442 Air Raid(DAG图的最小路径覆盖)

    题意: 有一个城镇,它的所有街道都是单行(即有向)的,并且每条街道都是和两个路口相连.同时已知街道不会形成回路. 可以在任意一个路口放置一个伞兵,这个伞兵会顺着街道走,依次经过若干个路口. 问最少需要 ...

随机推荐

  1. userdel 命令详解

    userdel  作用: 删除指定用户,以及用户相关的文件. 如不加选项,则仅删除用户账号,而不删除相关文件 选项: -f:强制删除用户,即时用户当前已登录 -r:删除用户的同时删除与用户相关的所有文 ...

  2. Discuz uc.key泄露导致代码注入漏洞

    漏洞描述:在Discuz中,uc_key是UC客户端与服务端通信的通信密钥,discuz中的/api/uc.php存在代码写入漏洞,导致黑客可写入恶意代码获取uckey,最终进入网站后台,造成数据泄漏 ...

  3. MySQL查询相关(初级)(全文重点)

    where 是约束条件 先找到表 from t1 where 条件 : 指的是把表里的数据,一条一条的记录取出来 然后 group by 分组, having 是过滤条件 指记录已经出来 聚合 cou ...

  4. Lucene.net(4.8.0) 学习问题记录三: 索引的创建 IndexWriter 和索引速度的优化

    前言:目前自己在做使用Lucene.net和PanGu分词实现全文检索的工作,不过自己是把别人做好的项目进行迁移.因为项目整体要迁移到ASP.NET Core 2.0版本,而Lucene使用的版本是3 ...

  5. Netty对Protocol Buffer多协议的支持(八)

    Netty对Protocol Buffer多协议的支持(八) 一.背景 在上篇博文中笔者已经用代码演示了如何在netty中使用Protocol Buffer,然而细心的用户可能会发现一个明显的不足之处 ...

  6. Shell脚本实现文件遍历和删除操作

    本文需要实现的功能如下:某文件夹下具有由按数字编号命名的文件夹,需要删除除最大编码外的文件. 具体实现 大致思路:循环遍历该文件夹下所有文件,正则匹配出最大编码文件:然后循环文件,删除除最大编码外的文 ...

  7. gitlab勾住rocket chat

    出于协作的要求, 需要在把gitlab的push event勾到rocket chat上面, 通知协作的其他人. BUT rocket chat提供的脚本没有具体的文件diff, so, 只好修改一下 ...

  8. 工作流调度器azkaban(以及各种工作流调度器比对)

    1:工作流调度系统的作用: (1):一个完整的数据分析系统通常都是由大量任务单元组成:比如,shell脚本程序,java程序,mapreduce程序.hive脚本等:(2):各任务单元之间存在时间先后 ...

  9. Google mobile test

    1. 现已更新至3.0+版本: 2. 应对版本频繁的迭代更新,进行[版本监控.持续更新.反馈,开发的单元测试] 1. 多关注金字塔的底层: 2. [集成测试, Espresso, EarlGrey] ...

  10. 入门干货之用DVG打造你的项目主页-Docfx、Vs、Github

    由于这三项技术涉及到的要点以及内容较多,希望大家有空能自己挖掘一下更多更深的用法. 0x01.介绍 VS,即VS2017以及以上版本,宇宙最好的IDE,集成了宇宙最有前景的平台,前阶段也支持了宇宙最好 ...