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

20699번 - Almost Balanced Tree 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB107413337.931%

문제

Consider a binary tree, each node has a weight equal to 1 or 2. The weight of a subtree is the sum of weights of all nodes in the subtree. The weight of an empty tree is 0.

The binary tree is almost balanced if for each node, the difference of weights of its children subtrees is at most 1 (if one of the children is missing, its weight is considered to be 0).

Here is an example of an almost balanced binary tree:

Your task is to build any almost balanced binary tree with exactly $A$ nodes of weight 1 and $B$ nodes of weight 2, or to say that it is impossible.

입력

The input contains two non-negative integers $A$ and $B$ (1ドル\le A+B\le 100,000円$).

출력

Assign indices from 1 to $A+B$ to the nodes of your tree, node 1 should be the root of the tree. Output $A+B$ lines, one for each node. Each line should contain three integers --- the weight of the node, and the indices of the left and the right children of the node. If the corresponding child is missing, output 0 instead.

If it is impossible to construct an almost balanced tree, output $-1$.

If there are multiple possible answers, output any one of them.

제한

예제 입력 1

6 3

예제 출력 1

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

예제 입력 2

0 2

예제 출력 2

-1

힌트

출처

ICPC > Regionals > Northern Eurasia > Northern Eurasia Finals > Northern Eurasia Finals 2020 (Online) A번

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

출처

대학교 대회

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

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