// Simple solution to assignment problem, // AKA minimum weighted bipartite matching, using Floyd-Warshall // to find negative-weight cycle to decrease cost. // Slower (O(n**4) than Hungarian method (O(m*m*n)). // May 26, 2007 BPW // Note: Internally the left column is padded with vertices so // the two columns have the same number of vertices. #include #include #define oo (999999) // infinity int m,n; // Number of left column and right column vertices int inWeight[50][50]; // Input weights int perm[50]; // Uses 0..n-1 for left column vertices, n..2*n-1 for right column vertices int FW[100][100],succ[100][100]; // For Floyd-Warshall void readInput() { int left,right,weight; scanf("%d %d",&m,&n); if (m>n) exit(0); for (left=0;left=m || right<0 || right>=n || weight<0 || weight>=oo) exit(0); if (weight=0; negCycleIndex++) ; return negCycleIndex; } int findInnermostCycle(int negCycleIndex) { // Find innermost cycle, just in case there are nested negative cycles. int left,right,i; int cycleCheck[50]; for (i=0;i