PivotOJ

House Numbering

시간 제한: 4000ms메모리 제한: 1024MB출처: BAPC 2022BOJ 25999

문제

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 uu and vv, and has hh 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 11 adjacent to intersection uu and end with house number hh at intersection vv, or house number 11 is adjacent to vv and house number hh is adjacent to uu. 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 nn (3n1053\leq n\leq 10^5), the number of intersections and number of streets.
  • nn lines with three integers uu, vv, and hh (uvu\neq v, 1u,vn1\leq u,v\leq n, 2h1092\leq h\leq 10^9) representing a street between intersections uu and vv that has hh 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
2
3

예제 2

입력
4
1 2 2
1 3 2
2 3 2
1 4 2
출력
impossible
이 문제는 채점 준비 중입니다. 테스트 데이터가 확보되면 제출이 가능합니다.