The input contains several test, and ends with EOF. For each test, the first line has an integer n,which is the number of people and target,next there is an integer matrix which size is n*n, the i-th row and the j-th colume of matrix means the time that i-th person needs to get target j. Next line is a number m, the number of the person who you want to be punished.ide
1<=m<n<=100 spa
3
1 2 3
2 3 4
3 4 5
3
3
3 3 3
2 2 2
1 1 1
3code
2 3
-1blog
1 #include<stdio.h>
2 #include<string.h>
3 int d[120][120],res[120],N,M,q[120]; 4 bool f[120][120],sta[120]; 5 bool find(int a) 6 { 7 for (int i=1;i<=N;i++) 8 { 9 if (f[a][i] && (!sta[i])) 10 { 11 sta[i]=true; 12 if (res[i]==0 || find(res[i])) 13 { 14 res[i]=a; 15 return true; 16 } 17 } 18 } 19 return false; 20 } 21 int hungary() 22 { 23 memset(res,0,sizeof(res)); 24 int Ans=0; 25 for (int i=1;i<=N;i++) 26 { 27 memset(sta,0,sizeof(sta)); 28 if (find(i)) Ans++; 29 } 30 return Ans; 31 } 32 int main() 33 { 34 while (scanf("%d",&N)!=EOF) 35 { 36 for (int i=1;i<=N;i++) 37 for (int j=1;j<=N;j++) 38 scanf("%d",&d[i][j]); 39 scanf("%d",&M); 40 int T=0; 41 for (int i=1;i<=N;i++) 42 { 43 memset(f,true,sizeof(f)); 44 for (int j=1;j<=N;j++) f[j][i]=false; 45 for (int j=1;j<=N;j++) f[M][j]=false; 46 for (int j=1;j<=N;j++) 47 for (int k=1;k<=N;k++) 48 if (d[j][k]>=d[M][i]) f[j][k]=false; 49 if (hungary()==(N-1)) q[++T]=i; 50 } 51 if (T==0) printf("-1\n"); 52 else
53 { 54 for (int i=1;i<T;i++) printf("%d ",q[i]); 55 printf("%d\n",q[T]); 56 } 57 } 58 return 0; 59 }