Air Raid

news/2024/10/18 8:29:00/

题目描述

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. 

输入描述:

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.

输出描述:

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.
示例1

输入

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

输出

2
1
#include<cstring>
#include<cstdio>
#include<cstdlib>
using namespace std;
int const maxn=122;
int n,m;
bool mat[maxn][maxn];
bool vis[maxn];
int mac[maxn];
bool match(int x)
{for(int i=1;i<=m;i++){if(mat[x][i]&&!vis[i]){vis[i]=1;if(!mac[i]||match(mac[i])){mac[i]=x;return 1;}}}return 0;
}
int main(){int a,b;int test;scanf("%d",&test);while(test--){scanf("%d%d",&m,&n);memset(mat,0,sizeof(mat));memset(mac,0,sizeof(mac));for(int i=0;i<n;i++){scanf("%d%d",&a,&b);mat[a][b]=1;}int ans=0;for(int i=1;i<=m;i++){memset(vis,0,sizeof(vis));if(match(i))ans++;}printf("%d\n",m-ans);}return 0;
}



http://www.ppmy.cn/news/702533.html

相关文章

C. Air Conditioner

链接&#xff1a;https://codeforces.com/contest/1304/problem/C Gildong owns a bulgogi restaurant. The restaurant has a lot of customers, so many of them like to make a reservation before visiting it. Gildong tries so hard to satisfy the customers that he …

Up in the Air-2

Speech on trip. How much does your life weigh(多重)? Imagine for a second that you’re carrying a backpack&#xff08;背一个包&#xff09;. I want you to feel the straps&#xff08;肩带&#xff09; on your shoulders. Feel them? I want you to pack it wit…

关于LiveData全面详解(附事件总线)

作者&#xff1a;苏火火 前言 MVVM 架构模式中&#xff0c;ViewModel 是不会持有宿主的信息&#xff0c;业务逻辑在 ViewModels 层中完成&#xff0c;而不是在 Activities 或 Fragments 中。LiveData 在里面担任数据驱动的作用&#xff1a; 以往我们使用 Handler&#xff0c;E…

Airflow简介

1、什么是Airflow Airflow 是一个 Airbnb 的 Workflow 开源项目&#xff0c;使用Python编写实现的任务管理、调度、监控工作流平台。Airflow 是基于DAG(有向无环图)的任务管理系统&#xff0c;可以简单理解为是高级版的crontab&#xff0c;但是它解决了crontab无法解决的任务…

Air Video

http://baike.baidu.com/view/8552809.htm#1 百度首页 | 登录注册 新闻网页贴吧知道MP3图片视频地图百科文库 帮助 首页自然文化地理历史生活社会艺术人物经济科技体育图片数字博物馆核心用户百科商城 求助编辑 Air Video 目录 简介 使用教程 展开 简介 使用教程 展开 编辑本段…

AirTest

Airetest是由网易游戏推出的一个跨平台的、基于图像识别的UI自动化测试框架&#xff0c;适用于游戏和APP&#xff0c;支持Windows、Android和ios&#xff0c;基于python进行编码。在此基础上&#xff0c;还推出了AiretestIDE&#xff0c;一款UI自动化测试编辑器&#xff0c;Poc…

Air Conditioners

题目链接&#xff1a;https://codeforces.com/problemset/problem/1547/E 这个题意比较容易理解&#xff0c;就是让我们求每个空格的最低温度&#xff0c;这道题目可以用最短路解决&#xff0c;我们可以让每两个相邻的点的距离为1&#xff0c;然后建立一个虚拟源点&#xff0c…

AIR是什么?.air文件如何打开?flex如何运行air文件

1 安装Adobe AIR 运行时&#xff0c;和java的JVM类似。 Adobe AIR 运行时允许在桌面运行AIR应用程序&#xff0c;脱离游览器的束缚。 下载安装文件 http://labs.adobe.com/downloads/air.html 在下载页面有样例程序&#xff08;Sample Applications&#xff09;http://labs…