hdu-1150 machine Schedule (binary graph matching minimum point coverage)

Source: Internet
Author: User

http://acm.hdu.edu.cn/showproblem.php?pid=1150

There are two kinds of machines, a machine has n mode, B machine has M mode, now have K tasks need to execute, do not switch a task machine will need to reboot once,

If task I is performed on machine A, a machine needs a corresponding pattern a, and if executed on machine B, machine A needs a pattern B.

Always is machine A in switch mode, now lets you arrange a reasonable task execution order, so that the machine restarts the fewest number of times.

An edge is attached to each task. Two the minimum vertex overlay is the least points that can be connected to all the edges and then converted to the maximum match.

The problem is that the initial state is 0, so if there is a task with a vertex of 0, there is no need to join because there is no cost.

1#include <cstdio>2#include <cstring>3#include <vector>4 using namespacestd;5 Const intMAXN = the;6 intn,m,k;7vector<int>G[MAXN];8 intLINK[MAXN];9 BOOLVIS[MAXN];Ten  One voidAdd_edge (intUintv) A { - G[u].push_back (v); -     //g[v].push_back (u); the } -  - BOOLDfsintu) - { +      for(intI=0; I<g[u].size (); i++) -     { +         intv=G[u][i]; A         if(!Vis[v]) at         { -vis[v]=true; -             if(link[v]==-1||DFS (Link[v])) -             { -link[v]=u; -                 return true; in             } -         } to     } +     return false; - } the intMain () * { $     //freopen ("A.txt", "R", stdin);Panax Notoginseng     inta,b,c; -      while(~SCANF ("%d", &n) &&N) the     { +scanf"%d%d",&m,&k); A          for(intI=0; i<maxn;i++) g[i].clear (); the          for(intI=0; i<k;i++) +         { -scanf"%d%d%d",&a,&b,&c); $             if(b>0&&c>0) $ Add_edge (b,c); -         } -         intans=0; thememset (link,-1,sizeof(link)); -          for(intI=0; i<n;i++)Wuyi         { thememset (Vis,0,sizeof(Vis)); -             if(Dfs (i)) ans++; Wu         } -printf"%d\n", ans); About     } $     return 0; -}

hdu-1150 machine Schedule (binary graph matching minimum point coverage)

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.