How to take input in this manner

How to take input in this manner. any hint how to take input like this and build tree

@anubhavb11 refer this for build function https://ide.codingblocks.com/s/251927