Question:
Send robots to the MARS Site for treasure hunt and give a directed graph without loops. robots can land on any point,
Then we explore other points along the road. Our task is to compute at least how many robots can access all points.Point can be repeated.
Ideas:
The minimum path overwrites, but the point can be repeated, it is required to pass the closure, with Floyd
/* ***********************************************Author :devilCreated Time :2016/5/17 16:45:13************************************************ */#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <cmath>#include <stdlib.h>using namespace std;const int N=510;int link[N],n;bool mp[N][N],vis[N];bool dfs(int u){ for(int i=1; i<=n; i++) { if(mp[u][i]&&!vis[i]) { vis[i]=1; if(link[i]==-1||dfs(link[i])) { link[i]=u; return 1; } } } return 0;}void floyd(){ for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) if(mp[i][j]==0) for(int k=1; k<=n; k++) if(mp[i][k]&&mp[k][j]) { mp[i][j]=1; break; }}int main(){ //freopen("in.txt","r",stdin); int m,x,y; while(~scanf("%d%d",&n,&m)&&(n+m)) { memset(link,-1,sizeof(link)); memset(mp,0,sizeof(mp)); while(m--) { scanf("%d%d",&x,&y); mp[x][y]=1; } floyd(); int ans=0; for(int i=1; i<=n; i++) { memset(vis,0,sizeof(vis)); ans+=dfs(i); } printf("%d\n",n-ans); } return 0;}
Poj2594 treasure transition ation (minimum path overwrite + transfer closure)