#include <stdio.h>
#include <stdlib.h>
struct Node
{
int value;
struct Node *left;
struct Node *right;
};
struct Node *new_node(int v)
{
struct Node
*n
= malloc(sizeof(*n
)); n->value = v;
n->left = NULL;
n->right = NULL;
return n;
}
struct Node *add_node(struct Node *n, int v)
{
if (n == NULL)
{
return new_node(v);
}
else
{
if (v < n->value)
{
n->left = add_node(n->left, v);
}
else
{
n->right = add_node(n->right, v);
}
return n;
}
}
int exists_node(struct Node *n, int v)
{
if (n == NULL)
{
return 0;
}
else
{
if (v < n->value)
{
return exists_node(n->left, v);
}
else if (n->value < v)
{
return exists_node(n->right, v);
}
else
{
return 1;
}
}
}
int min_node(struct Node *n)
{
if (n->left == NULL)
{
return n->value;
}
else
{
return min_node(n->left);
}
}
int main() {
int i;
int v;
int n;
FILE *f;
struct Node *t;
t = NULL;
f
= fopen("input.txt", "r"); for (i = 0; i < n; i++)
{
t = add_node(t, v);
}
if (exists_node(t, v))
{
}
else
{
}
if (t != NULL)
{
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCnN0cnVjdCBOb2RlCnsKICAgIGludCB2YWx1ZTsKICAgIHN0cnVjdCBOb2RlICpsZWZ0OwogICAgc3RydWN0IE5vZGUgKnJpZ2h0Owp9OwoKc3RydWN0IE5vZGUgKm5ld19ub2RlKGludCB2KQp7CiAgICBzdHJ1Y3QgTm9kZSAqbiA9IG1hbGxvYyhzaXplb2YoKm4pKTsKICAgIG4tPnZhbHVlID0gdjsKICAgIG4tPmxlZnQgPSBOVUxMOwogICAgbi0+cmlnaHQgPSBOVUxMOwogICAgcmV0dXJuIG47Cn0KCnN0cnVjdCBOb2RlICphZGRfbm9kZShzdHJ1Y3QgTm9kZSAqbiwgaW50IHYpCnsKICAgIGlmIChuID09IE5VTEwpCiAgICB7CiAgICAgICAgcmV0dXJuIG5ld19ub2RlKHYpOwogICAgfQogICAgZWxzZQogICAgewogICAgICAgIGlmICh2IDwgbi0+dmFsdWUpCiAgICAgICAgewogICAgICAgICAgICBuLT5sZWZ0ID0gYWRkX25vZGUobi0+bGVmdCwgdik7CiAgICAgICAgfQogICAgICAgIGVsc2UKICAgICAgICB7CiAgICAgICAgICAgIG4tPnJpZ2h0ID0gYWRkX25vZGUobi0+cmlnaHQsIHYpOwogICAgICAgIH0KICAgICAgICAKICAgICAgICByZXR1cm4gbjsgCiAgICB9Cn0KCmludCBleGlzdHNfbm9kZShzdHJ1Y3QgTm9kZSAqbiwgaW50IHYpCnsKICAgIGlmIChuID09IE5VTEwpCiAgICB7CiAgICAgICAgcmV0dXJuIDA7CiAgICB9CiAgICBlbHNlCiAgICB7CiAgICAgICAgaWYgKHYgPCBuLT52YWx1ZSkKICAgICAgICB7CiAgICAgICAgICAgIHJldHVybiBleGlzdHNfbm9kZShuLT5sZWZ0LCB2KTsKICAgICAgICB9CiAgICAgICAgZWxzZSBpZiAobi0+dmFsdWUgPCB2KQogICAgICAgIHsKICAgICAgICAgICAgcmV0dXJuIGV4aXN0c19ub2RlKG4tPnJpZ2h0LCB2KTsKICAgICAgICB9CiAgICAgICAgZWxzZQogICAgICAgIHsKICAgICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgfQogICAgfQp9CgppbnQgbWluX25vZGUoc3RydWN0IE5vZGUgKm4pCnsKICAgIGlmIChuLT5sZWZ0ID09IE5VTEwpCiAgICB7CiAgICAgICAgcmV0dXJuIG4tPnZhbHVlOwogICAgfQogICAgZWxzZQogICAgewogICAgICAgIHJldHVybiBtaW5fbm9kZShuLT5sZWZ0KTsKICAgIH0KfQoKaW50IG1haW4oKSB7CiAgICBpbnQgaTsKICAgIGludCB2OwogICAgaW50IG47CiAgICBGSUxFICpmOwogICAgc3RydWN0IE5vZGUgKnQ7CiAgICAKICAgIHQgPSBOVUxMOwogICAgZiA9IGZvcGVuKCJpbnB1dC50eHQiLCAiciIpOwogICAgZnNjYW5mKGYsICIlZCIsICZuKTsKICAgIGZvciAoaSA9IDA7IGkgPCBuOyBpKyspCiAgICB7CiAgICAgICAgZnNjYW5mKGYsICIlZCIsICZ2KTsKICAgICAgICB0ID0gYWRkX25vZGUodCwgdik7CiAgICB9ICAgIAogICAgZmNsb3NlKGYpOwogICAgCiAgICBwcmludGYoIj4gIik7CiAgICBzY2FuZigiJWQiLCAmdik7CiAgICAKICAgIGlmIChleGlzdHNfbm9kZSh0LCB2KSkKICAgIHsKICAgICAgICBwcmludGYoInllc1xuIik7CiAgICB9CiAgICBlbHNlCiAgICB7CiAgICAgICAgcHJpbnRmKCJub1xuIik7CiAgICB9CiAgICAKICAgIGlmICh0ICE9IE5VTEwpCiAgICB7CiAgICAgICAgcHJpbnRmKCIlZFxuIiwgbWluX25vZGUodCkpOwogICAgfQoKICAgIHJldHVybiAwOwp9