The problem of Nanyang 239----Matchmaker "Hungarian algorithm"

Source: Internet
Author: User

1 /*2 Hungarian Algorithm Template questions3 adjacency table Implementation, adjacency matrix timeout4 Maximum matching problem5  */6#include <cstdio>7#include <vector>8#include <cstring>9 using namespacestd;Ten Const intMAXN =505; Onevector<int> V[MAXN];//x = v[i][j] means I can be matched with x A intVIS[MAXN],MATCH[MAXN];//Vis[i] means I have been accessed (matched) to prevent repeated access to a point in each DFS, x = match[i] means x now and I match - BOOLDfsintx) - { the      for(inti =0; I < v[x].size (); ++i) -     { -         intt =V[x][i]; -         if(!Vis[t]) +         { -VIS[T] =1; +             if(Match[t] = =-1||DFS (match[t])) A{Match[t] = x;return true;} at         } -     } -     return false; - } - intHungaryintN) - { in     intAns =0; -      for(inti =1; I <= N; ++i) to     { +memset (Vis,0,sizeofvis); -         if(Dfs (i)) + +ans; the     } *     returnans; $ }Panax Notoginseng intMain () - { the     intt,n,m,x,y; +scanf"%d",&t); A      while(t--) the     { +scanf"%d%d",&n,&m); -          for(inti =1; I <= N; ++i) $ v[i].clear (); $memset (Match,-1,sizeofmatch); -          while(m--) -         { thescanf"%d%d",&x,&y); - v[x].push_back (y);Wuyi         } theprintf"%d\n", Hungary (n)); -     } Wu     return 0; -}

The problem of Nanyang 239----Matchmaker "Hungarian algorithm"

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.