1 solutions

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

    C++ :

    #include <bits/stdc++.h>
    #define N 100005
    using namespace std;
    
    struct Node{
        int l,r;
    } a[N];
    
    void dfs(int fa){
        
        if (a[fa].l) dfs(a[fa].l);
        cout << fa << endl;
        if (a[fa].r) dfs(a[fa].r);
    }
    
    int main(){
        int n;
        cin >> n;
        for (int i = 1;i<=n;i++){
            cin >> a[i].l >> a[i].r;
        }
        dfs(1);
        return 0;
    }
    
    • 1

    Information

    ID
    351
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    10
    Tags
    # Submissions
    2
    Accepted
    2
    Uploaded By