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

25999번 - House Numbering 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 (추가 시간 없음) 1024 MB56272754.000%

문제

You are addicted to the latest world-simulation game: Building A Perfect City. In your current play-through, you have created a city that has an equal number of streets and intersections. All that is left is to number the houses in every street.

The city is represented by a connected graph with intersections and streets. Every street is a connection between two intersections $u$ and $v,ドル and has $h$ houses which are all on one side of the street. There is at most one street between two intersections. There are two ways to number the houses in this street: either you start with house number 1ドル$ adjacent to intersection $u$ and end with house number $h$ at intersection $v,ドル or house number 1ドル$ is adjacent to $v$ and house number $h$ is adjacent to $u$. To avoid confusion, you want to ensure that no intersection has two adjacent houses with the same number.

Find a way to number the houses in every street that satisfies this property (or report that it is impossible).

입력

The input consists of:

  • One line with an integer $n$ (3ドル\leq n\leq 10^5$), the number of intersections and number of streets.
  • $n$ lines with three integers $u,ドル $v,ドル and $h$ ($u\neq v,ドル 1ドル\leq u,v\leq n,ドル 2ドル\leq h\leq 10^9$) representing a street between intersections $u$ and $v$ that has $h$ houses.

It is guaranteed that every intersection is reachable from every other intersection. There is at most one street between any two intersections.

출력

If it is impossible, output "impossible". Otherwise, output for each street (in the same order as the input) a number representing the intersection where the house numbering starts.

If there are multiple valid solutions, you may output any one of them.

제한

예제 입력 1

3
1 2 2
2 3 9
3 1 3

예제 출력 1

1
2
3

예제 입력 2

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

예제 출력 2

impossible

힌트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > Benelux Algorithm Programming Contest > BAPC 2022 H번

  • 문제를 만든 사람: Reinier Schmiermann
(追記) (追記ここまで)

출처

대학교 대회

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

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