Poj2594 treasure transition ation (minimum path overwrite + transfer closure)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.