1 solutions

  • 0
    @ 2026-11-18 18:59:41

    C++ :

    #include <bits/stdc++.h>
    using namespace std;
    
    const int MAXN = 105;
    int val[MAXN], lc[MAXN], rc[MAXN];
    int n, x, cnt = 0;
    
    void inorder(int u) {
        if (u == 0) return;
        inorder(lc[u]);
        cnt++;
        if (val[u] == x) {
            cout << cnt << endl;
            exit(0);
        }
        inorder(rc[u]);
    }
    
    int main() {
        cin >> n >> x;
        for (int i = 1; i <= n; i++) {
            cin >> val[i] >> lc[i] >> rc[i];
        }
        inorder(1);
        return 0;
    }
    
    • 1

    Information

    ID
    356
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    10
    Tags
    # Submissions
    1
    Accepted
    1
    Uploaded By