najimCseJu

Loj 1400 Statement

Jul 14th, 2016
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. Employment is a contract between two parties, one being the employer and the other being the employee. Now assume that there are n companies who require one employee each and there are n candidates. All the candidates interviewed in each of the companies and eventually they have different preferences over the companies and the companies have different preferences over the candidates.
  2.  
  3. So, you are given the task to assign each candidate to each company such that the employment scheme is stable. A scheme is stable if there is no pair (candidatei, companyj) and (candidatex, companyy) where
  4.  
  5. a) Candidatei prefers companyy more than companyj and
  6. b) Companyy prefers candidatei more than candidatex.
  7.  
  8. As there can be many solutions, any valid one will do.
  9.  
  10. Input
  11. Input starts with an integer T (≤ 30), denoting the number of test cases.
  12.  
  13. Each case starts with a line containing an integer n (1 ≤ n ≤ 100). The candidates are numbered from 1 to n and the companies are numbered from n+1 to 2n.
  14.  
  15. Each of the next n lines contains n distinct integers from n+1 to 2n, where the ith line contains the company preference for the ith candidate (1 ≤ i ≤ n).
  16.  
  17. Each of the next n lines contains n distinct integers from 1 to n, where the ith line contains the candidate preference for the company which is denoted by n+i (1 ≤ i ≤ n).
  18.  
  19. Output
  20. For each case, print the case number and the (candidate, company) pairs. As there can be many solutions any valid one will do. And you can output the pairs in any order but print those as (candidate, company) pair.
Advertisement
Add Comment
Please, Sign In to add comment