HDU 10,542 Maximum Match of the graph

Source: Internet
Author: User

Idea: template problem, note is the graph, so the final result to be divided by 2. With 1500 points, the adjacency matrix is timed out and the adjacency table is used.

1#include <cstdio>2#include <iostream>3#include <cstring>4#include <algorithm>5#include <cmath>6#include <cstdlib>7#include <sstream>8#include <iomanip>9#include <vector>Ten#include <map> One#include <Set> A#include <queue> - using namespacestd; - Const intMOD = 1e9 +7; the  -typedefLong LongLL; -typedef unsignedLong LongULL; -  + Const intMAXN = the+5; -vector<int>G[MAXN]; + intLINK[MAXN]; A BOOLCHECK[MAXN]; at intN; -  - BOOLDfsintu) { -      for(inti =0; I < g[u].size (); ++i) { -         if(!Check[g[u][i]]) { -Check[g[u][i]] =true; in             if(Link[g[u][i]] = =-1||DFS (Link[g[u][i])) { -Link[g[u][i]] =u; to                 return true; +             } -         } the     } *     return false; $ }Panax Notoginseng  - intHugarian () { the     intAns =0; +memset (link,-1,sizeof(link)); A      for(inti =0; I < n; ++i) { thememset (check,0,sizeof(check)); +         if(Dfs (i)) + +ans; -     } $     returnans; $ } -  - intMain () { the      while(SCANF ("%d", &n) = =1){ -          for(inti =0; I < n; ++i) {Wuyi g[i].clear (); the         } -          for(inti =0; I < n; ++i) { Wu             intj,k; -scanf"%d: (%d)", &j,&k);//This place was first read into the char* and then assigned to J,k, the Mle About              while(k--){ $                 intx; -scanf"%d",&x); - g[j].push_back (x); - G[x].push_back (j); A             } +         } theprintf"%d\n", Hugarian ()/2); -     } $     return 0; the}

HDU 10,542 Maximum Match of the graph

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.