思路:
简单模拟读懂题就会了。
代码:
#include <bits/stdc++.h>
#define fastio ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define debug(a) cout << "debug : " << (#a) << " = " << a << endl
using namespace std;
typedef long long ll;
typedef pair<int, vector<int>> PII;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int mod = 998244353;
vector<int> a[N];
int b[N];
int main()
{
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
int x, k;
a[i].push_back(x);
cin >> k;
while (k--)
{
cin >> x;
a[i].push_back(x);
}
}
int i = 1;
while (m--)
{
int op, x;
cin >> op >> x;
if (op == 0)
i = a[i][x];
else if (op == 1)
{
b[x] = i;
cout << i << endl;
}
else
i = b[x];
}
cout << i << endl;
return 0;
}