Air Raid HDU
来源:互联网 发布:阿里云解析新网域名 编辑:程序博客网 时间:2024/06/06 02:56
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.
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.
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.
24 33 41 32 3331 31 22 3
21
#include<bits/stdc++.h>using namespace std;const int M=16000;struct aa{ int u,v,next;} edge[1600000];int pre[M],n,cnt,mached[M],used[M],m;void add(int u,int v){ edge[cnt].u=u; edge[cnt].v=v; edge[cnt].next=pre[u]; pre[u]=cnt++;}bool findx(int u){ for(int i=pre[u]; i!=-1; i=edge[i].next) { int v=edge[i].v; if(used[v]==-1) { used[v]=0; if(mached[v]==-1||findx(mached[v])) { mached[v]=u; return 1; } } } return 0;}int hungary(){ memset(mached,-1,sizeof(mached)); int ans=0; for(int i=0; i<=n; i++) { memset(used,-1,sizeof(used)); if(findx(i))ans++; } return ans;}int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); memset(pre,-1,sizeof(pre)); cnt=0; for(int i=0;i<m;i++) { int u,v; scanf("%d%d",&u,&v); add(u,v); } printf("%d\n",n-hungary()); }}
阅读全文
0 0
- hdu 1151 Air Raid
- hdu 1151 Air Raid
- HDU 1151 Air Raid
- HDU 1151Air Raid
- Hdu 1151 - Air Raid
- Air Raid hdu
- hdu 1151 Air Raid
- hdu 1151 Air Raid
- hdu 1151 Air Raid
- hdu 1151 Air Raid
- HDU 1151 Air Raid
- HDU 1151 Air Raid
- hdu 1151 Air Raid
- hdu 1151 Air Raid
- Air Raid HDU
- hdu/hdoj 1151 Air Raid
- hdu 1151 Air Raid 匹配
- hdu acm 1151 Air Raid
- [BZOJ]3294: [Cqoi2011]放棋子 DP+组合数学
- jquery originalEvent与event关系
- leetcode 371. Sum of Two Integers 位运算 + 加法操作
- WebSocket+多线程python socket网页版实时在线聊天实现
- JVM的简单实现
- Air Raid HDU
- [VCS-git]-01.git安装及常用客户端命令
- 二维码
- 动态规划-188. Best Time to Buy and Sell Stock IV
- bzoj 4936: [Ceoi2016]match
- stm32f103 spi slave从机模式miso需要上拉
- Recover the Smallest Number (30)
- 使用ViewPager实现屏幕滑动
- lambda表达式杂谈