int main(void) { int edges[MAXEDGES*2], ne, nv; int capacity[MAXEDGES], flow[MAXEDGES], cut[MAXVERTICES]; int source, sink, p, q, i, j, ret; /* * Use this algorithm to find a maximal complete matching in a * bipartite graph. */ ne = 0; nv = 0; source = nv++; p = nv; nv += 5; q = nv; nv += 5; sink = nv++; for (i = 0; i < 5; i++) { capacity[ne] = 1; ADDEDGE(source, p+i); } for (i = 0; i < 5; i++) { capacity[ne] = 1; ADDEDGE(q+i, sink); } j = ne; capacity[ne] = 1; ADDEDGE(p+0,q+0); capacity[ne] = 1; ADDEDGE(p+1,q+0); capacity[ne] = 1; ADDEDGE(p+1,q+1); capacity[ne] = 1; ADDEDGE(p+2,q+1); capacity[ne] = 1; ADDEDGE(p+2,q+2); capacity[ne] = 1; ADDEDGE(p+3,q+2); capacity[ne] = 1; ADDEDGE(p+3,q+3); capacity[ne] = 1; ADDEDGE(p+4,q+3); /* capacity[ne] = 1; ADDEDGE(p+2,q+4); */ qsort(edges, ne, 2*sizeof(int), compare_edge); ret = maxflow(nv, source, sink, ne, edges, capacity, flow, cut); printf("ret = %d\n", ret); for (i = 0; i < ne; i++) printf("flow %d: %d -> %d\n", flow[i], edges[2*i], edges[2*i+1]); for (i = 0; i < nv; i++) if (cut[i] == 0) printf("difficult set includes %d\n", i); return 0; }
void Kruskal( int D[][10], int v, int V[][2], int E[][2] ) { int min = D[0][0], v1 = 0, v2 = 0; while( count < v ) { min = 2000; v1 = 0; v2 = 0; for( int i = 0; i < v; i++ ) //find minimum in the distance matrix { for( int j = i+1; j < v; j++ ) { if( D[i][j] < min ) { min = D[i][j]; v1 = i; v2 = j; } } } D[v1][v2] = D[v2][v1] = MAX; if( ADDVERT( v1, v2, V ) == 1 ) { ADDEDGE( v1+1, v2+1, E ); } //else cout<<"\nEdge not added"; } }
}inline void Init(){ int i=n=getint();m=getint(); static pair<int,int>R[N]; for(i=-1;++i!=n;)R[i]=make_pair(getint(),i); sort(R,R+n); for(a[R[0].second]=i=0;++i!=n;)a[R[i].second]=a[R[i-1].second]+(R[i].first!=R[i-1].first); while(--i)ADDEDGE(getint()-1,getint()-1); }