#include <cstdio>
#include <queue>
#include <map>

using namespace std;

struct bintree {
	int val;
	struct bintree *left, *right;
};

int main(){
	struct bintree bt;
	bt.val = 1;
	bt.left = new struct bintree();
	bt.right = new struct bintree();
	//bt.left->left = bt.left->right =NULL;
	bt.left->val = 10000;

	//bt.left->right = bt.right->right =NULL;
	bt.right->val = 100;

	bt.left->right = new struct bintree();
	bt.left->right->val = 10;


	queue<struct bintree*> que;
	map<struct bintree*,bool> visited;
	que.push(&bt);

	int sum=0;
	while(!que.empty()){
		struct bintree* bt = que.front();
		sum += bt->val;
		que.pop();

		if(bt->left != NULL && visited.find(bt->left) == visited.end()){
			visited[bt->left] = true;
			que.push(bt->left);
		}

		if(bt->right != NULL && visited.find(bt->right) == visited.end()){
			visited[bt->right] = true;
			que.push(bt->right);
		}
	}

	printf("%d\n",sum);
}