L2-040 哲哲打游戏

这题读懂题目之后就发现它很呆

#include <bits/stdc++.h>

using namespace std;

const int N = 100010, M = 110;
vector<int> g[N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        int k;
        cin >> k;
        int u = i;
        g[u].push_back(-1);
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            g[u].push_back(v);
        }
    }   
    int cur = 1; 
    map<int, int> onfile;
    for (int i = 0; i < m; i++) {
        int op, x;
        cin >> op >> x;
        if (op == 0) {
            cur = g[cur][x];
        } else if (op == 1) {
            onfile[x] = cur;
            cout << cur << "\n";
        } else {
            cur = onfile[x];
        }
    }
    cout << cur;

    return 0;
}

//1 -> 4 -> 3 -> 7 -> 8 -> 3 -> 5 -> 9 -> 10。
posted @ 2022-04-16 17:51  Xxaj5  阅读(41)  评论(0编辑  收藏  举报