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