Logo
(追記) (追記ここまで)

18875번 - Favorite Colors 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB271776331.658%

문제

Each of Farmer John's $N$ cows (1ドル\le N\le 2\cdot 10^5$) has a favorite color. The cows are conveniently labeled 1ドル\ldots N$ (as always), and each color can be represented by an integer in the range 1ドル\ldots N$.

There exist $M$ pairs of cows $(a,b)$ such that cow $b$ admires cow $a$ (1ドル\le M\le 2\cdot 10^5$). It is possible that $a=b,ドル in which case a cow admires herself. For any color $c,ドル if cows $x$ and $y$ both admire a cow with favorite color $c,ドル then $x$ and $y$ share the same favorite color.

Given this information, determine an assignment of cows to favorite colors such that the number of distinct favorite colors among all cows is maximized. As there are multiple assignments that satisfy this property, output the lexicographically smallest one (meaning that you should take the assignment that minimizes the colors assigned to cows 1ドル\ldots N$ in that order).

입력

The first line contains $N$ and $M$.

The next $M$ lines each contain two space-separated integers $a$ and $b$ (1ドル\le a,b\le N$), denoting that cow $b$ admires cow $a$. The same pair may appear more than once in the input.

출력

For each $i$ in 1ドル\ldots N,ドル output the color of cow $i$ in the desired assignment on a new line.

제한

예제 입력 1

9 12
1 2
4 2
5 8
4 6
6 9
2 9
8 7
8 3
7 1
9 4
3 5
3 4

예제 출력 1

1
2
3
1
1
2
3
2
3

힌트

In the image below, the circles with bolded borders represent the cows with favorite color 1.

출처

Olympiad > USA Computing Olympiad > 2019-2020 Season > USACO 2020 US Open Contest > Gold 2번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /