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

28366번 - Distance Code 서브태스크다국어채점 준비 중

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB0000.000%

문제

Your task is to create a program that can be used in two ways: as an encoder and as a decoder.

The encoder is given a tree of $n$ nodes and it removes all nodes from the tree. On each step, the encoder may remove any leaf from the current tree.

The decoder is given a list of distances between successively removed nodes by the encoder, and it has to reconstruct the original structure of the tree.

The decoder has to create any tree that has the same structure as the original tree (more precisely, it has to be isomorphic to the original tree).

입력

The first line has an integer $t$ that is either 1ドル$ (encoder) or 2ドル$ (decoder).

The second line has an integer $n$: the number of nodes in the tree. The nodes are numbered 1,2,ドル\dots,n$.

If $t=1,ドル there are then $n-1$ lines that describe the tree. Each line has two integers $a$ and $b$: there is an edge between nodes $a$ and $b$.

If $t=2,ドル there is only one line that has $n-1$ integers: the distances between successively removed nodes.

출력

If $t=1,ドル the encoder has to print a permutation of numbers 1,2,ドル\dots,n$: the order in which the nodes are removed from the tree.

If $t=2,ドル the decoder has to print $n-1$ lines that describe the structure of the tree.

제한

서브태스크

번호배점제한
121

2ドル≤n≤10$

247

2ドル≤n≤500$

332

2ドル≤n≤10^5$

예제 입력 1

1
3
1 2
2 3

예제 출력 1

1 3 2

예제 입력 2

2
3
2 1

예제 출력 2

2 3
1 3

힌트

출처

Olympiad > Nordic Olympiad in Informatics > NOI 2019 A번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

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

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