<s>[INST] ### Problem
You are given a binary tree where each node has the following structure:

```cpp
struct Node {
    int val;
    Node* left;
    Node* right;
    Node(int x) : val(x), left(NULL), right(NULL) {}
};
```

Write a function `isSameTree` that takes the roots `p` and `q` of two binary trees and checks if they are the same. Two trees are the same if they are structurally identical, and the nodes have the same values.

*   Example 1:

    *   Input: `p = [1,2,3], q = [1,2,3]`
    *   Output: `true`
*   Example 2:

    *   Input: `p = [1,2], q = [1,null,2]`
    *   Output: `false`
*   Example 3:

    *   Input: `p = [1,2,1], q = [1,1,2]`
    *   Output: `false`

### Solution

#### C++ Solution

```cpp
class Solution {
public:
    bool isSameTree(Node* p, Node* q) {
        // If both trees are empty, they are the same
        if (p == nullptr && q == nullptr) {
            return true;
        }
        // If one tree is empty and the other is not, they are not the same
        if (p == nullptr || q == nullptr) {
            return false;
        }
        // If the values of the nodes are different, the trees are not the same
        if (p->val != q->val) {
            return false;
        }
        // Recursively check the left and right subtrees
        return isSameTree(p->left, q->left) && isSameTree(p->right, q->right);
    }
};
```

#### Explanation

The provided C++ solution defines a function `isSameTree` that checks if two binary trees `p` and `q` are the same. The function uses a recursive approach to compare the trees.

Here's a step-by-step breakdown:

1.  **Base Case**: If both trees are empty (`p` and `q` are both `nullptr`), the function returns `true`, indicating that they are the same.
2.  **Mismatched Trees**: If one tree is empty and the other is not, the function returns `false`, indicating that they are not the same.
3.  **Value Comparison**: If the values of the current nodes are different (`p->val != q->val`), the function returns `false`, indicating that the trees are not the same.
4.  **Recursive Check**: If the values match, the function recursively checks the left and right subtrees by calling `isSameTree(p->left, q->left)` and `isSameTree(p->right, q->right)`. If both recursive calls return `true`, the function returns `true`, indicating that the trees are the same.

This solution ensures that all nodes are compared, and the trees are considered the same only if they have the same structure and node values.

You can use this function by creating a `Solution` object and calling the `isSameTree` method, passing the roots of the two binary trees as arguments. For example:

```cpp
int main() {
    // Create nodes for the first tree
    Node* p = new Node(1);
    p->left = new Node(2);
    p->right = new Node(3);

    // Create nodes for the second tree
    Node* q = new Node(1);
    q->left = new Node(2);
    q->right = new Node(3);

    // Create a Solution object
    Solution solution;

    // Check if the trees are the same
    bool result = solution.isSameTree(p, q);

    // Print the result
    std::cout << "Are the trees the same?[/INST]