RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0334 파일 입출력

Milking Order

Gold II 골드 II
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Farmer John's \(N\) cows (\(1 \leq N \leq 10^5\)), numbered \(1 \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 \(M\) observations about his cows'
social structure (\(1 \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 \(X\) for which his milking order meets the conditions outlined in the first
\(X\) observations. If multiple milking orders satisfy these first \(X\)
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 \(x\) is lexicographically smaller than an ordering \(y\)
if for some \(j\), \(x_i = y_i\) for all \(i < j\) and \(x_j < y_j\) (in other words,
the two orderings are identical up to a certain point, at which \(x\) is smaller
than \(y\)).

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

Problem credits: Jay Leeds

제약

Problem credits: Jay Leeds

입력 형식

The first line contains \(N\) and \(M\). The next \(M\) lines each describe an
observation. Line \(i+1\) describes observation \(i\), and starts with the number of
cows \(m_i\) listed in the observation followed by the list of \(m_i\) integers
giving the ordering of cows in the observation. The sum of the \(m_i\)'s is at
most \(200,000\).

출력 형식

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

파일 입력 / 출력
이 문제는 표준 입출력을 사용하지 않습니다. 프로그램은 다음 파일을 읽고 써야 합니다:
입력을 읽을 파일 milkorder.in
출력을 쓸 파일 milkorder.out
예제 1
입력
4 3
3 1 2 3
2 4 2
3 3 4 1
출력
1 4 2 3
설명

Here, Farmer John has four cows and should milk cow 1 before cow 2 and cow 2
before cow 3 (the first observation), cow 4 before cow 2 (the second
observation), and cow 3 before cow 4 and cow 4 before cow 1 (the third
observation). The first two observations can be satisfied simultaneously, but
Farmer John cannot meet all of these criteria at once, as to do so would require
that cow 1 come before cow 3 and cow 3 before cow 1.

This means there are two possible orderings: 1 4 2 3 and 4 1 2 3, the first
being lexicographically smaller.

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2017-2018 > US Open > Gold

태그

평가 및 의견

Milking Order

개요
출제자 난이도 Gold II 골드 II 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Milking Order

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8