An Unfair Game
Time Limit: 6000/3000 MS (Java/Others)
Memory Limit: 128000/64000 KB (Java/Others)
Problem Description
There are n people and n target, everyone should get one target, no two people get the same target, the last one who get the target should be punished, there is only one person will be punished, so if more than one person are the last, no one will be punished. As the judge, you know exactly how much time that people i getting target j will spend, but there are no people know how much time he needs. You need to arrange for a target to everyone, and you want the i-th people to be punished (Now you know why it is an unfair game?).
Input
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.
1<=m<n<=100
Output
Each test print one line, the number of the target that m-th person gets, if there are more than one answer, print all of them. If there is no answer, only print -1.
Sample Input
3 1 2 3 2 3 4 3 4 5 3 3 3 3 3 2 2 2 1 1 1 3
Sample Output
2 3 -1
Source
UUZ
Manager
/****************************
* author:crazy_石头
* date:2014/04/30
* time: 2888 ms
* algorithm:dfs
* Pro:UVA
***************************/
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std; #define INF INT_MAX #define eps 1e-8 #define A system("pause") #define rep(i,h,n) for(int i=(h);i<=(n);i++) #define ms(a,b) memset((a),(b),sizeof(a)) #define lson l , m , rt << 1 #define rson m + 1 , r , rt << 1 | 1 #define LL long long const int N=100+5; const int maxm=30; int map[N][N],new_map[N][N],v[N],l[N],n,m; inline int dfs(int p) { rep(i,0,n-1) if (new_map[p][i]&&!v[i]) { v[i]=1; if (l[i]==-1 ||dfs(l[i])) { l[i]=p; return 1; } } return 0; } inline int fuck() { int ans=0; ms(l,-1); rep(i,0,n-1) if (i!=m) { ms(v,0); if (!dfs(i)) return 0; } return 1; } int main() { while (cin>>n) { int flag=1; rep(i,0,n-1) rep(j,0,n-1) cin>>map[i][j]; cin>>m; m--; rep(i,0,n-1) { rep(k,0,n-1) rep(j,0,n-1) if (k!=m && j!=i && map[k][j]