poj2594:Treasure Exploration

来源:互联网 发布:渭南网络电视台 编辑:程序博客网 时间:2024/04/30 01:00

2594:Treasure Exploration

        
总时间限制:
6000ms
内存限制:
65536kB
描述
Have you ever read any book about treasure exploration? Have you ever see any film about treasure exploration? Have you ever explored treasure? If you never have such experiences, you would never know what fun treasure exploring brings to you.
Recently, a company named EUC (Exploring the Unknown Company) plan to explore an unknown place on Mars, which is considered full of treasure. For fast development of technology and bad environment for human beings, EUC sends some robots to explore the treasure.
To make it easy, we use a graph, which is formed by N points (these N points are numbered from 1 to N), to represent the places to be explored. And some points are connected by one-way road, which means that, through the road, a robot can only move from one end to the other end, but cannot move back. For some unknown reasons, there is no circle in this graph. The robots can be sent to any point from Earth by rockets. After landing, the robot can visit some points through the roads, and it can choose some points, which are on its roads, to explore. You should notice that the roads of two different robots may contain some same point.
For financial reason, EUC wants to use minimal number of robots to explore all the points on Mars.
As an ICPCer, who has excellent programming skill, can your help EUC?
输入
The input will consist of several test cases. For each test case, two integers N (1 <= N <= 500) and M (0 <= M <= 5000) are given in the first line, indicating the number of points and the number of one-way roads in the graph respectively. Each of the following M lines contains two different integers A and B, indicating there is a one-way from A to B (0 < A, B <= N). The input is terminated by a single line with two zeros.
输出
For each test of the input, print a line containing the least robots needed.
样例输入
1 02 11 22 00 0
样例输出
112
大致题意:    给出一个由n个顶点m条边组成的无回路有向图。求最少可以同时存在多少路径,使得这些路径可以覆盖所有的点(注:每个都点可以被多条路径覆盖)。大致思路:    最小路径覆盖的一点小小变形,由于这里的点可以被重复覆盖,所以除了按照普通求最小路径覆盖的方式建立二分图以外,还要对原图用floyd求一遍传递闭包,并更新二分图。接下来用点数n减去最大匹配得到的就是答案。#include<stdio.h>#include<string.h>#define N 1010int map[N][N],mode[N],vis[N];int n,m;void floyd()// 用floyd求一遍传递闭包,并更新二分图。{int i,j,k;for(k=1;k<=n;k++){for(j=1;j<=n;j++){for(i=1;i<=n;i++){if(map[i][k]&&map[k][j])map[i][j]=1;}}} } int find(int x)//寻找增广路! 找到返回1,否则返回0!{int i,j;for(i=1;i<=n;i++){ if(map[x][i]&&!vis[i]) { vis[i]=1; if(!mode[i]||find(mode[i]))//i 点 没有和另一部分匹配或 和i配对的点 没有匹配! { mode[i]=x; return 1; } }}return 0;}int main(){int i,j;while(scanf("%d%d",&n,&m)&&(n||m)){int x,y;memset(map,0,sizeof(map));memset(mode,0,sizeof(mode));for(i=1;i<=m;i++){scanf("%d%d",&x,&y);if(x&&y)map[x][y]=1;}floyd();int s=0;for(i=1;i<=n;i++){memset(vis,0,sizeof(vis));if(find(i))//增广路 s++;}printf("%d\n",n-s);}return 0;}

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 我和别人没离婚的老婆在一起怎么办 老婆起诉我离婚我不想理怎么办 上大学的孩子对考试无所谓怎么办 家里的人对我已经没有信心了怎么办 我是做股票配资的找不到客户怎么办 心理健康类的课程总是选不了怎么办 孩子该上初三了英语基础差怎么办 初二学生辍学半年又想上学怎么办 保险用的小红本丢了怎么办 孩子的小红本丢了怎么办 宝宝打针的小红本丢了怎么办 居民养老保险小红本丢了怎么办 小学六年级素质报告单丢了怎么办 西安小学素质报告册有b怎么办 辽宁省干部在线学习时长不够怎么办 鬼火一代发动机在中间卡死怎么办 医疗权与患者隐私权想冲突怎么办 登录法宣在线出现贴号失效怎么办 黔微普法在线竞答成绩不合格怎么办 怎么办刮过胡子后又长了? 网贷暴力催收警察也没办法怎么办 儿子把我车抵押给了高利贷怎么办 水泵开机五分钟左右就跳闸怎么办 离婚了她说过的不好你该怎么办 偏侧咀嚼笑时一边嘴歪怎么办 三相四线开关前地线有电怎么办 高三学生重度抑郁怎么办马高考了 潞城报名系统密码找不回来怎么办 绵阳富乐实验小学外地入学怎么办 联想手机升级失败开不了机怎么办 电脑桌面上的微信图标不见了怎么办 精子总活力和运动力低怎么办 精子少畸形高怎么办能治好吗 小米无人机只能飞500米远怎么办 考察课作弊被老师抓了怎么办 手机中木马病毒了钱被盗走了怎么办 在搜不到校园网的情况下怎么办 刚买小鸡第四天晚上一直叫怎么办 碘131第四天晚上吃太撑了怎么办 出现请点击画面开始进行校准怎么办 大学毕业后才发现荒废了学业怎么办