"HDU 1150" machine Schedule (binary graph matching)

Source: Internet
Author: User

The different modes of the machine for the point, for each job, build two side a machine required mode <->B machine required mode.

The problem is converted to the minimum point overlay, and then the minimum point of the binary graph is used to overwrite = = maximum match, using the Hungarian algorithm.

#include <cstdio> #include <cstring>const int n=105<<1;const int m=1001<<1;struct edge{int to, Next;} E[m];int head[n],tot;void Add (int u,int v) {e[tot].to=v;e[tot].next=head[u];head[u]=tot++;} void Init () {Tot=0;memset (head,-1,sizeof head);} int n,vis[n],link[n];int find (int u) {for (int i=head[u];~i;i=e[i].next) {int v=e[i].to;if (!vis[v]) {vis[v]=1;if (!link[ v]| | Find (Link[v])) {Link[v]=u;return 1;}}} return 0;} int solve () {memset (link,0,sizeof link), int ans=0;for (int i=1;i<=n;i++) {memset (vis,0,sizeof Vis), if (Find (i)) ans++ ;} return ans;} int main () {int k,m,u,v;while (scanf ("%d", &n), n) {init (); scanf ("%d%d", &m,&k), while (k--) {scanf ("%d%d%d", &M,&U,&V); add (u,v+n); add (v+n,u);} printf ("%d\n", Solve ());}}

  

"HDU 1150" machine Schedule (binary graph matching)

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.