Tree construction

3.8

12 votes
Graph, Tree, Depth First Search, Graphs, Algorithms, Greedy Algorithms, Binary Search
Problem

You are given a rooted tree with n vertices (the root is vertex 1). The beautifulness of a tree sum of each vertex's subtree size.

You have lost the tree but you know n and the beautifulness of the tree is m. Can you construct a rooted tree with n vertices (the root is vertex 1) and beautifulness m?

In a rooted tree, a subtree of vertex v is all vertices like u that the path from u to root includes v.

Input format

The first line contains two integers n and m denoting the number of the tree's vertices and their beautifulness.

Output format

If there is no tree with n vertices and m beautifulness, print 1. Otherwise, print n1 lines where each contains edges of the constructed tree.

Constraints

1n105

1m1018

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

The sum of subtree sizes for constructed tree is: subtree(1)+subtree(2)+subtree(3)+subtree(4)=4+1+2+1=8.

Editor Image

?