hdu/hdoj 1150 Machine Schedule

来源:互联网 发布:淘宝网狗狗衣服 编辑:程序博客网 时间:2024/04/30 04:12

最小点覆盖,把任务看成连线;


#include<iostream>#include <vector>#include <stdio.h>using namespace std;#define MAXN 1001vector <int> map[MAXN];int path[MAXN];int vst[MAXN];int n,m,k;//n,m??????????С int t;bool dfs(int v){    int i;    for(i=0;i<map[v].size();i++)    {        if(!vst[map[v][i]])        {            vst[map[v][i]]=1;            if(path[map[v][i]]==-1||dfs(path[map[v][i]]))            {                path[map[v][i]]=v;                return true;            }        }    }    return false;}int hungary(){    int i;    int cnt=0;    memset(path,-1,sizeof(path));    for(i=0;i<n;i++)    {        memset(vst,0,sizeof(vst));        if(dfs(i))            cnt++;    }    return cnt;}int main(){        int p,pp,ppp;    while (scanf("%d",&n)!=EOF && n)    {        scanf("%d %d",&m,&k);        for(int i=0;i<MAXN;++i)        {            map[i].clear();        }        for (int i=0; i<k; ++i)        {            scanf("%d %d %d",&p,&pp,&ppp);            if (pp!=0 && ppp!=0)                map[pp].push_back(ppp);        }                        cout<<hungary()<<endl;    }}


原创粉丝点击