TREEORD

10
1 2 5 4 3 8 6 9 10 7
4 5 2 8 1 9 7 3 10 6
5 4 1 3 2 8 7 6 9 10
6
1 2 4 5 3 6
4 5 2 6 3 1
4 2 5 1 3 6
6
1 2 4 5 3 6
4 5 2 6 1 3
4 2 5 1 6 3
8
1 2 4 5 3 6 8 7
4 5 2 6 1 3 8 7
4 2 5 1 6 3 8
8
1 2 4 5 3 6 8 7
4 5 2 6 1 3 8 7
4 2 5
8
1 2 4 5 3 6 8 7
4 5 2 6 1 3
4 2 5
8
1 2 4 5 3
oihoi
1 2 4 5 3 6
4 5 2 6 3 1
4 2 5 1 6 3
1 2 4 5 3
4 5 2 3 1
4 2 5 1 3
6
1 2 4 5 3 6
4 5 2 6 3 1
4 2 5 1 6 3
1 2 4 5 3 6
4 5 2 6 3 1
4 2 5 1 3 6
6
123456
123456
123456
oaoa
jancuk
10
1 2 5 4 3 8 6 9 10 7
4 5 2 8 1 9 7 3 10 6
5 4 1 3 2 8 7 6 9 10
2
1 2
2 1
2 1
2
1 2
2 1
1 2
6
1 2 4 5 3 6
4 5 2 6 1 3
4 2 5 1 6 3
6
1 2 4 5 3 6
4 5 2 6 3 1
4 2 5 1 3 6
5
1 2 4 5 3
4 5 2 3 1
4 2 5 1 3
5
1 2 4 5 3
4 5 2 6 3 1
4 2 5 1 3
5
1 2 4 5 3
4 5 2 6 3
4 2 5 1 3
5
1 2 4 5 3 6 
4 5 2 6 3 1
4 2 5 1 3 6
5
1 2 4 5 3
4 5 2 3 1
4 2 5 1 3
5
1 2 3 4 5
5 4 3 2 1
5 4 3 2 1
3
1 2 3
3 1 2
2 1 3
1
1
1
1
10
1 2 3 8 9 5 10 3 6 7
8 9 4 10 5 2 6 7 3 1
8 4 9 10 5 2 1 3 6 7

#include
#include
typedef struct inord{
	int v;
	struct inord* next;
}inord;
int trav(int* o1,int* o2,inord* o3,int n)
{
	if(o1[0]!=o2[n-1]) return 0;

	if(n==1)
	{
		if(o1[0]==o2[0] && o2[0]==o3->v) return 1;
		else return 0;
	}
	inord* cur=o3;
	int ret=1;
	int i;
	while(cur)
	{
		if(cur->v==o1[0]) break;
		cur=cur->next;
	}
	if(cur)
	{
		int leftnum=0;
		if(cur->next!=NULL)
		{
			//right child exists
			inord* right=cur->next;
			int rightv=o2[n-2];
			for(i=0;inext,leftnum);
		}
		return ret;
	}
	else return 0;
}
int main(){
	
int n,i;
scanf("%d",&n);
int* o1,*o2;
inord *o3;
o1= (int*) malloc( sizeof(int)*n);
o2= (int*) malloc( sizeof(int)*n);
o3= (inord*) malloc( sizeof(inord));
inord* cur=o3,*prev=NULL;
for(i=0;iv);
	if(prev)prev->next=cur;
	cur->next=NULL;
	prev=cur;
	if(i!=n-1)
		cur=(inord*) malloc(sizeof(inord));
}
int t=trav(o1,o2,o3,n);
if(t) printf("yes\n");
else printf("no\n");
return 0;
}
#include
#include
typedef struct inord{
	int v;
	struct inord* next;
}inord;
int trav(int* o1,int* o2,inord* o3,int n)
{
	if(o1[0]!=o2[n-1]) return 0;

	if(n==1)
	{
		if(o1[0]==o2[0] && o2[0]==o3->v) return 1;
		else return 0;
	}
	inord* cur=o3;
	int ret=1;
	int i;
	while(cur)
	{
		if(cur->v==o1[0]) break;
		cur=cur->next;
	}
	if(cur)
	{
		int leftnum=0;
		if(cur->next!=NULL)
		{
			//right child exists
			inord* right=cur->next;
			int rightv=o2[n-2];
			for(i=0;inext,leftnum);
		}
		return ret;
	}
	else return 0;
}
int main(){
	
int n,i;
scanf("%d",&n);
int* o1,*o2;
inord *o3;
o1= (int*) malloc( sizeof(int)*n);
o2= (int*) malloc( sizeof(int)*n);
o3= (inord*) malloc( sizeof(inord));
inord* cur=o3,*prev=NULL;
for(i=0;iv);
	if(prev)prev->next=cur;
	cur->next=NULL;a
	prev=cur;
	if(i!=n-1)
		cur=(inord*) malloc(sizeof(inord));
}
int t=trav(o1,o2,o3,n);
if(t) printf("yes\n");
else printf("yen");
return 0;
}
10
1 2 3 8 9 5 10 3 6 7
8 9 4 10 5 2 6 7 3 1
8 4 9 10 5 2 1 3 6 7
def check(pre, post, ino):
	#print pre
	#print post
	if ( len(pre) != len(post) ):
		return False
	if ( pre[0] != post[-1] ):
		return False
	if ( len(pre) == 1 ): 
		return True
	left  = pre[1]
	right = post[-2]
	if ( left != right ):
		a = check(pre[1:pre.index(right)], post[0:post.index(left) + 1], ino)
		b = check(pre[pre.index(right):],  post[post.index(left) + 1:-1], ino)
		return a and b
	elif ( left == right and left != pre[0] ):
		return check(pre[pre.index(right):], post[0:post.index(left) + 1], ino)
	else:
		return True

length   = int(raw_input())
preorder = [int(x) for x in raw_input().split()]
postorder = [int(x) for x in raw_input().split()]
inorder = [int(x) for x in raw_input().split()]

if check(preorder, postorder, inorder):
	print "yes"
else:
	print "no"
class Node:
	def __init__(self, data):
		self.data = data
		self.left = None
		self.right = None
def build(pre, ino, start, end):
	if ( start > end ): return None
	tnode = Node(pre[build.stat])
	build.stat += 1
	if ( start == end ):
		return tnode
	for i in range(start, end + 1):
		if ino[i] == tnode.data: break
	tnode.left   = build( pre, ino, start, i - 1 )
	tnode.right  = build( pre, ino, i + 1, end )
	return tnode

def dfs(node, ls):
	if node.left != None:
		dfs(node.left, ls)
	if node.right != None:
		dfs(node.right, ls)
	ls.append(node.data)

length   = int(raw_input())
preorder = [int(x) for x in raw_input().split()]
postorder = [int(x) for x in raw_input().split()]
inorder = [int(x) for x in raw_input().split()]

build.stat = 0
tree = build(preorder, inorder,  0, length - 1)
created = []
dfs(tree, created)

ac = "yes"
for i in range(0, length):
	if created[i] != postorder[i]:
		ac = "no"
		break
print ac
5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
asd
1
1
1
1
10
1 2 3 8 9 5 10 3 6 7
8 9 4 10 5 2 7 6 3 1
8 4 9 10 5 2 1 3 6 7
5
1 2 4 5 3
4 5 2 6 3 1
4 2 5 1 3
5
1 2 4 5 3 6 
4 5 2 6 3 1
4 2 5 1 3 6
5
1 2 4 5 3
4 5 2 6 3
4 2 5 1 3
5
1 2 3 4 5
5 4 3 2 1
5 4 3 2 1
#include 
#include 


typedef struct inord{
    int v;
    struct inord* next;
    }inord;

int trav(int* o1, int* o2, inord* o3, int n){

    if(o1[0] != o2[n-1]){
        return 0;
    }

    if(n == 1){
        if(o1[0] == o2[0] && o2[0] == o3->v){
            return 1;
        }else {
            return 0;
        }
    }

    inord* cur = o3;
    int ret = 1;
    int i;

    while(cur){
        if(cur->v == o1[0]) break;
        cur = cur->next;
    }

    if(cur){
        int leftnum = 0;

        if(cur->next == NULL){
            inord* right = cur->next;

            int rightv = o2[n-2];

            for(i = 0; inext, leftnum);
        }

        return ret;
    }
    else return 0;
}
int main(){
    int n, i;

    scanf("%d", &n);

    int* o1, *o2;

    inord *o3;

    o1 = (int*) malloc(sizeof(int)*n);
    o2 = (int*) malloc(sizeof(int)*n);
    o3 = (inord*) malloc(sizeof(inord));

    inord* cur = o3, *prev = NULL;

    for(i = 0; iv);

        if(prev)prev->next = cur;
        cur->next = NULL;
        prev = cur;

        if(i != n-1){
            cur = (inord*) malloc(sizeof(inord));
        }
    }

    int t = trav(o1, o2, o3, n);

    if(t){
        printf("yes\n");
    } else{
        printf("no\n");
    }

    return 0;
}
1 2 4 5 3 6 8 7
4 5 2 6 1 3 8 7
4 2 5
1 2 3 4 5 6
6 5 4 3 2 1
6 5 4 3 2 1
6
1 2 3 4 5 6
6 5 4 3 2 1
6 5 4 3 2 1
6
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6

6
1 2 4 5 3 6
4 5 2 6 3 1
4 2 5 1 6 3

6
1 2 3 4 5 6
6 5 4 3 2 1
6 5 4 3 2 1
4
4 2 1 3
3 1 2 4
1 2 4 3
6
1 2 4 5 3 6
4 5 2 6 3 1
4 2 5 1 3 6
5
1 2 3 4 5
5 4 3 2 1
5 4 3 2 1
4
4 2 1 3
3 1 2 4
1 2 4 3
6
1 2 3 4 5 6
6 5 4 3 2 1
6 5 4 3 2 1