SPOJ runtime error (SIGXFSZ)

I am getting runtime error (SIGXFSZ) in the question 1790. Binary Search Heap Construction.

Here is my code.

#include<iostream>
#include<cstdio>
using namespace std;
class name
{
	public:
	int p;
	string l;
	name* left;
	name* right;
	name* parent;
	name(int tp,string tl,name *pa)
	{
		parent=pa;
		p=tp;
		l=tl;
		left=NULL;
		right=NULL;
	}
};
void print(name *p);
name* rotate(name* p,name* parent,name* root)
{
	if (p->parent==NULL) return root;
	if (p->p>p->parent->p)
	{
		if (p->parent->left==p)
		{
			p->parent->left=p->right;
			if (p->right)
				p->right->parent=p->parent;
			p->right=p->parent;
			if (p->parent->parent)
				p->parent->parent->left=p;
			p->parent=p->parent->parent;
			p->right->parent=p;
	
		}
		else
		{
			p->parent->right=p->left;
			if (p->left)
				p->left->parent=p->parent;
			p->left=p->parent;
			if (p->parent->parent)
				p->parent->parent->right=p;
			p->parent=p->parent->parent;
			p->left->parent=p;
		}
		if (p->parent==NULL)
		{
			root=p;
			return root;
		}
		else
			return rotate(p,p->parent,root);
	}
	return root;
}
class treap
{
	public:
	name* root;
	treap()
	{
		root=NULL;
	}
	void insert(int tp,string tl)
	{
		if (root==NULL)
		{
			root=new name(tp,tl,NULL);
		}
		else
		{
			name* p=root;
			while (1)
			{
				if (tl<p->l&&p->left==NULL)
				{
					p->left=new name(tp,tl,p);
					rotate(p->left,p->left->parent,root);
					return;
				}
				else if (tl<p->l&&p->left!=NULL)
				{
					p=p->left;
				}
				else if (tl>p->l&&p->right==NULL)
				{
					p->right=new name(tp,tl,p);
					root=rotate(p->right,p->right->parent,root);	
					return;
				}
				else if (tl>p->l&&p->right!=NULL)
				{
					p=p->right;
				}
			}
		}
	}
};
void print(name *p)
{
	printf("(");
	if (p->left!=NULL)
	{
		print(p->left);
	}
	printf("%s/%d",p->l.c_str(),p->p);
	if (p->right!=NULL)
	{
		print(p->right);		
	}
	printf(")");
}
string in()
{
	char c,ans[100];
	scanf("%c",&c);
	int k=0;
	while (c==' ')scanf("%c",&c);	
	while (c!='/')
	{
		ans[k++]=c;
		scanf("%c",&c);	
	}
	ans[k]=0;
	return string(ans);
}
int main()
{
	int n,i,tp;
	string tl;
	scanf("%d",&n);
	while (n!=0)
	{
		treap tree;
		for (i=0;i<n;i++)
		{
			
			tl=in();
			
			scanf("%d",&tp);
			tree.insert(tp,tl);
		}
		print(tree.root);
		printf("\n");
		scanf("%d",&n);
	}
	return 0;
}

Please Help.

I am still stuck on this question.

Please help.

i have the same problem did you find any solution ?
please answer me

Just check ur code, how it will allocate memory.