2057: [USACO 2022 February Contest Silver] Problem 1. Redistributing Gifts
文件提交:无需freopen
内存限制:256 MB
时间限制:2.000 S
评测方式:普通裁判
命题人:
提交:2
解决:1
题目描述
Farmer John has gifts labeled for his cows, also labeled (). Each cow has a wishlist, which is a permutation of all gifts such that the cow prefers gifts that appear earlier in the list over gifts that appear later in the list.
FJ was lazy and just assigned gift to cow for all . Now, the cows have gathered amongst themselves and decided to reassign the gifts such that after reassignment, every cow ends up with the same gift as she did originally, or a gift that she prefers over the one she was originally assigned.
For each from to , compute the most preferred gift cow could hope to receive after reassignment.
输入
The first line contains . The next lines each contain the preference list of a cow. It is guaranteed that each line forms a permutation of .
输出
Please output lines, the -th of which contains the most preferred gift cow could hope to receive after reassignment.
样例输入
4
1 2 3 4
1 3 2 4
1 2 3 4
1 2 3 4
样例输出
1
3
2
4
提示
In this example, there are two possible reassignments:
- The original assignment: cow receives gift , cow receives gift , cow receives gift , and cow receives gift .
- Cow receives gift , cow receives gift , cow receives gift , and cow receives gift .
Observe that both cows and cannot hope to receive better gifts than they were originally assigned. However, both cows and can.
SCORING:
- Test cases 2-3 satisfy .
- Test cases 4-11 satisfy no additional constraints.