#389
Unrated
Milking Order
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Farmer John's NN cows (1N1051 \leq N \leq 10^5), numbered 1N1 \ldots N as always, happen to have too much time on their hooves. As a result, they have worked out a complex social hierarchy related to the order in which Farmer John milks them every morning.

After weeks of study, Farmer John has made MM observations about his cows' social structure (1M50,0001 \leq M \leq 50,000). Each observation is an ordered list of some of his cows, indicating that these cows should be milked in the same order in which they appear in this list. For example, if one of Farmer John's observations is the list 2, 5, 1, Farmer John should milk cow 2 sometime before he milks cow 5, who should be milked sometime before he milks cow 1.

Farmer John's observations are prioritized, so his goal is to maximize the value of XX for which his milking order meets the conditions outlined in the first XX observations. If multiple milking orders satisfy these first XX conditions, Farmer John believes that it is a longstanding tradition that cows with lower numbers outrank those with higher numbers, so he would like to milk the lowest-numbered cows first. More formally, if multiple milking orders satisfy these conditions, Farmer John would like to use the lexicographically smallest one. An ordering xx is lexicographically smaller than an ordering yy if for some jj, xi=yix_i = y_i for all i<ji < j and xj<yjx_j < y_j (in other words, the two orderings are identical up to a certain point, at which xx is smaller than yy).

Please help Farmer John determine the best order in which to milk his cows.

입력

The first line contains NN and MM. The next MM lines each describe an observation. Line i+1i+1 describes observation ii, and starts with the number of cows mim_i listed in the observation followed by the list of mim_i integers giving the ordering of cows in the observation. The sum of the mim_i's is at most 200,000200,000.

출력

Output NN space-separated integers, giving a permutation of 1N1 \ldots N containing the order in which Farmer John should milk his cows.

예제 입력 1

4 3
3 1 2 3
2 4 2
3 3 4 1

예제 출력 1

1 4 2 3
코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.