#include <bits/stdc++.h>
using namespace std;

struct TreeNode{
	int val;
vector<TreeNode*>child;
	TreeNode(int val):child({}),val(val){};
};

TreeNode* construct(vector<int>&arr){
		stack<TreeNode*>st;
		TreeNode* root;
	if(arr[0]!=-1){
			root = new TreeNode(arr[0]);
			
	}
	
	

	st.push(root);
	//potentially wrong :
	//did not handle popping for -1 val
	//root->children should be attached to the last st val
	for(int i = 1;i<arr.size();i++){
		if(arr[i]!=-1){
			TreeNode* par = st.top();
			TreeNode* newChild= new TreeNode(arr[i]);
			par->child.push_back(newChild);
			st.push(newChild);
		}else{
			st.pop();
		}
	}
	return root;
}
void display(TreeNode* root){
	//pw
	if(root!=NULL){
		cout<<root->val<<"->";
	}
	
	//
	for(TreeNode* child : root->child){
		//TreeNode* child=root->child[i];
		cout<<child->val<<",";
	}
	
	cout<<"."<<endl;
    
    for(TreeNode* child:root->child){
		display(child);
	}
}
int main() {
   vector<int>arr =  {10,20,50,-1,60,-1,-1,30,70,-1,80,100,-1,110,-1,-1,90,-1,-1,40,120,-1,130,-1,-1,-1};
   TreeNode* root = construct(arr);
   display(root);
   return 0;
}