6 条题解

  • 5
    @ 2023-12-19 17:45:15
    #include<iostream>
    #include<algorithm>
    #include<cmath>
    #include<vector>
    #include<set>
    #include<string>
    #include<iomanip>
    #include<cstring>
    #include<ctime>
    #include<unordered_map>
    #include<stack>
    #include<queue>
    //*****************************************************************************************************************
    //                .-~~~~~~~~~-._       _.-~~~~~~~~~-.
    //            __.'              ~.   .~              `.__
    //          .'//                  \./                  \\`.
    //        .'//                     |                     \\`.
    //      .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-. \\`.
    //    .'//.-"                 `-.  |  .-'                 "-.\\`.
    //  .'//______.============-..   \ | /   ..-============.______\\`.
    //.'______________________________\|/______________________________`.
    //*****************************************************************************************************************
    using namespace std;
    const int o = 1e7 + 10;
    typedef pair<long, long>ll;
    int a[o],s[o],b[o];
    int main()
    {
        int n, q;
        cin >> n >> q;
        while(n--)
        {
            int x, y;
            cin >> x >> y;
            a[y] = x;//用指针把终点和起点连接起来
        }
        while (q--)
        {
            int t,c=0;
            cin >> t;//用于找每一个终点的起点(比较拗口,大概就是,知道是4,用t找3,然后t为3,然后找0)
            b[c++] = t;
            while (a[t])
            {
                b[c++] = a[t];//逆向保存路径,便于输出
                t = a[t];
            }
            for (int i = c; i >= 0; i--)
            {
                cout << b[i] << " ";
            }
            cout << endl;//比起其他的题目,这个题目不用\n就能过
        }
    }
    
    • @ 2023-12-19 20:22:31

      nb

信息

ID
964
时间
2000ms
内存
256MiB
难度
6
标签
递交数
350
已通过
106
上传者