#GD0000170. Xổ số Ba số Bảy (Three Sevens)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Xổ số Ba số Bảy (Three Sevens)
Three Sevens
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A lottery was held for days. Day has distinct participants. Exactly one participant wins each day, and a winner is forbidden from participating on any later day. Find any possible list of winners consistent with the participation lists, or print -1 if impossible.
Input
The first line contains . For every day , a line contains , followed by a line of pairwise distinct participant IDs.
Output
Print -1 if no solution exists. Otherwise print winner IDs , each appearing on day and on no later day.
Subtasks
- Subtask 1 (20 points): ; ; ; mỗi days không trùng số hiệu; .
- Subtask 2 (30 points): ; ; ; mỗi days không trùng số hiệu; .
- Subtask 3 (50 points): ; ; ; mỗi days không trùng số hiệu; .
Examples
Input
3
2
1 2
2
2 3
2
3 4
Output
1 2 4
Explanation
On day , select participant . On day , participant is in a later day, so select . On day , participant appears later, so select . The winner list is valid and no winner participates on a later day.