Binary graph matching (Hungarian algorithm) POJ 3041 asteroids

Source: Internet
Author: User

Topic Portal

1 /*2 Test Instructions: Each time a row or column of obstacles can be eliminated, the minimum number of times required. 3 Hungarian algorithm: The row and column as two sets, when there are obstacles connected with an edge, the problem is converted to the minimum number of coverage = = Binary Graph maximum match4 Introduction to Fun:http://blog.csdn.net/dark_scope/article/details/88805475 */6#include <cstdio>7#include <algorithm>8#include <cstring>9#include <vector>Ten using namespacestd; One  A Const intMAXN = 5e2 +Ten; - Const intINF =0x3f3f3f3f; -vector<int>G[MAXN]; the BOOLVIS[MAXN]; - intLK[MAXN]; -  - BOOLDFS (intu) + { -      for(intI=0; I<g[u].size (); ++i) +     { A         intv =G[u][i]; at         if(!Vis[v]) -         { -VIS[V] =true; -             if(Lk[v] = =-1||DFS (Lk[v])) -             { -LK[V] = u;return true; in             } -         } to     } +     return false; - } the  * intHungaryintN) $ {Panax Notoginseng     intres =0; memset (LK,-1,sizeof(LK)); -      for(intI=1; i<=n; ++i) the     { +memset (Vis,false,sizeof(Vis)); A         if(DFS (i)) res++; the     } +  -     returnRes; $ } $  - intMainvoid)//POJ 3041 Asteroids - { the //freopen ("poj_3041.in", "R", stdin); - Wuyi     intN, K; the      while(SCANF ("%d%d", &n, &k) = =2) -     { Wu          for(intI=1; i<=n; ++i) g[i].clear (); -          for(intI=1; i<=k; ++i) About         { $             intx, y; scanf ("%d%d", &x, &y); - g[x].push_back (y); -         } -  Aprintf ("%d\n", Hungary (n)); +     } the  -     return 0; $}

Binary graph matching (Hungarian algorithm) POJ 3041 asteroids

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.