static void coarsen_match ( v_data * graph, /* graph to be matched */ ex_vtx_data* geom_graph, /* another graph (with coords) on the same nodes */ int nvtxs, /* number of vertices in graph */ int nedges, /* number of edges in graph */ int geom_nedges, /* number of edges in geom_graph */ v_data ** cgraph, /* coarsened version of graph */ ex_vtx_data ** cgeom_graph, /* coarsened version of geom_graph */ int *cnp, /* number of vtxs in coarsened graph */ int *cnedges, /* number of edges in coarsened graph */ int *cgeom_nedges, /* number of edges in coarsened geom_graph */ int **v2cvp, /* reference from vertices to coarse vertices */ int **cv2vp, /* reference from vertices to coarse vertices */ int dist2_limit ) /* * This function gets two graphs with the same node set and * constructs two corresponding coarsened graphs of about * half the size */ { int *mflag; /* flag indicating vtx matched or not */ int nmerged; /* number of edges contracted */ int *v2cv; /* reference from vertices to coarse vertices */ int *cv2v; /* reference from vertices to coarse vertices */ int cnvtxs; /* Allocate and initialize space. */ mflag = N_NEW(nvtxs, int); /* Find a maximal matching in the graphs */ nmerged = maxmatch(graph, geom_graph, nvtxs, mflag, dist2_limit); /* Now construct coarser graph by contracting along matching edges. */ /* Pairs of values in mflag array indicate matched vertices. */ /* A negative value indicates that vertex is unmatched. */ *cnp = cnvtxs = nvtxs - nmerged; *v2cvp = v2cv = N_NEW(nvtxs, int); *cv2vp = cv2v = N_NEW(2 * cnvtxs, int); makev2cv(mflag, nvtxs, v2cv, cv2v); free(mflag); *cnedges = make_coarse_graph(graph, nvtxs, nedges, cgraph, cnvtxs, v2cv, cv2v); *cgeom_nedges = make_coarse_ex_graph(geom_graph, nvtxs, geom_nedges, cgeom_graph, cnvtxs, v2cv, cv2v); }
int main() { int n, m; while (EOF != scanf("%d%d", &n, &m)) { for (int i = 0; i <= n; ++i) V[i] = -1; nE = 0; for (int i = 0, a, b; i < m; ++i) { scanf("%d%d", &a, &b); addEdge(a, b); } printf("%d\n", n - maxmatch(n, n)); } return 0; }
int main() { int n,m; int t; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); for(int i = 0; i < n; ++i) { for(int j = 0; j < m; ++j) map[i][j] = getchar(); getchar(); } memset(row, -1, sizeof(row)); memset(col, -1, sizeof(col)); cnt_row = cnt_col = 0; for(int i = 0; i < n; ++i) { for(int j = 0; j < m; ++j) { if(map[i][j] == '*' && row[i][j] == -1) { for(int k = j; map[i][k] == '*' && k < n; ++k) row[i][k] = cnt_row; cnt_row++; } if(map[j][i] == '*' && col[j][i] == -1) { for(int k = j; map[k][i] == '*' && k < n; ++k) col[k][i] = cnt_col; cnt_col++; } } } memset(path, false, sizeof(path)); for(int i = 0; i < n; ++i) for(int j = 0; j < m; ++j) if(map[i][j] == '*') path[ row[i][j] ][ col[i][j] ] = true; printf("%d\n", maxmatch()); } return 0; }
int main() { int n, m, k; while (EOF != scanf("%d", &n)) { if (n == 0) break; scanf("%d%d", &m, &k); memset(mat, 0, sizeof(mat)); while (k--) { int i, x, y; scanf("%d%d%d", &i, &x, &y); if (x * y) mat[x][y] = 1; // 0 模式下无需转换 } int ans = maxmatch(n, m, mat, m1, m2); printf("%d\n", ans); } return 0; }
int main() { int n; while (EOF != scanf("%d", &n)) { memset(mat, 0, sizeof(mat)); for (int i = 0, id, c, d; i < n; ++i) { scanf("%d: (%d) ", &id, &c); while (c--) { scanf("%d", &d); mat[id][d] = 1; mat[d][id] = 1; } } printf("%d\n", n - maxmatch(n) / 2); } return 0; }
int main() { int i,a,n,m,num; while(scanf("%d%d",&n,&m)!=EOF) { nx=n;ny=m; memset(g,0,sizeof(g)); for(i=0;i<n;i++) { scanf("%d",&num); while(num--) { scanf("%d",&a); g[i][a-1]=1; } } printf("%d\n",maxmatch()); } return 0; }
int main() { int runs, p, n; scanf("%d", &runs); while (runs--) { memset(mat, 0, sizeof(mat)); scanf("%d%d", &p, &n); for (int i = 0, c, y; i < p; ++i) { scanf("%d", &c); while (c--) { scanf("%d", &y); mat[i][y-1] = 1; } } n1 = p, n2 = n; int ans = maxmatch(); if (ans == p) puts("YES"); else puts("NO"); } return 0; }
void coarsen1 ( struct vtx_data **graph, /* array of vtx data for graph */ int nvtxs, /* number of vertices in graph */ int nedges, /* number of edges in graph */ struct vtx_data ***pcgraph, /* coarsened version of graph */ int *pcnvtxs, /* number of vtxs in coarsened graph */ int *pcnedges, /* number of edges in coarsened graph */ int **pv2cv, /* pointer to v2cv */ int igeom, /* dimension for geometric information */ float **coords, /* coordinates for vertices */ float **ccoords, /* coordinates for coarsened vertices */ int using_ewgts /* are edge weights being used? */ ) { extern double coarsen_time; extern double match_time; double time; /* time routine is entered */ int *v2cv; /* maps from vtxs to cvtxs */ int *mflag; /* flag indicating vtx matched or not */ int cnvtxs; /* number of vtxs in coarse graph */ int nmerged; /* number of edges contracted */ double seconds(); int maxmatch(); void makev2cv(), makefgraph(); time = seconds(); /* Allocate and initialize space. */ v2cv = smalloc((nvtxs + 1) * sizeof(int)); mflag = smalloc((nvtxs + 1) * sizeof(int)); /* Find a maximal matching in the graph. */ nmerged = maxmatch(graph, nvtxs, nedges, mflag, using_ewgts, igeom, coords); match_time += seconds() - time; /* Now construct coarser graph by contracting along matching edges. */ /* Pairs of values in mflag array indicate matched vertices. */ /* A zero value indicates that vertex is unmatched. */ /* makecgraph(graph, nvtxs, pcgraph, pcnvtxs, pcnedges, mflag, *pv2cv, nmerged, using_ewgts, igeom, coords, ccoords); makecgraph2(graph, nvtxs, nedges, pcgraph, pcnvtxs, pcnedges, mflag, *pv2cv, nmerged, using_ewgts, igeom, coords, ccoords); */ makev2cv(mflag, nvtxs, v2cv); sfree(mflag); cnvtxs = nvtxs - nmerged; makefgraph(graph, nvtxs, nedges, pcgraph, cnvtxs, pcnedges, v2cv, using_ewgts, igeom, coords, ccoords); *pcnvtxs = cnvtxs; *pv2cv = v2cv; coarsen_time += seconds() - time; }